Commit 2ec1345c authored by Waweic's avatar Waweic 💬
Browse files

Add Settings and changeable Start page

parent 3f732414
......@@ -32,6 +32,8 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.preference:preference:1.0.0'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
......
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="rocks.ism.decentral.geminiclient">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
......@@ -9,16 +11,27 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
<activity android:name=".SettingsActivity"
android:label="Settings"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity"/>
</activity>
<activity
android:name=".MainActivity"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="gemini" />
</intent-filter>
</activity>
......
package rocks.ism.decentral.geminiclient
import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.widget.EditText
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.preference.PreferenceManager
import kotlinx.coroutines.*
import java.net.URI
class GeminiClient(applicationContext: Context, val mainContentView: TextView, val uriField: EditText) {
class GeminiClient(val applicationContext: Context, val mainContentView: TextView, val uriField: EditText) {
val connection : GeminiConnection = GeminiConnection()
val renderer : GeminiRenderer = GeminiRenderer(mainContentView, this)
val responseHandler : GeminiResponseHandler = GeminiResponseHandler(renderer, applicationContext, this)
val sharedPreferences= PreferenceManager.getDefaultSharedPreferences(applicationContext)
private val history: MutableList<URI> = mutableListOf()
init {
PreferenceManager.setDefaultValues(applicationContext, R.xml.preferences, false)
}
fun goToPage(uri: URI) {
if(uri.toString() == "about:preferences") {
val intent = Intent(applicationContext, SettingsActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
applicationContext.startActivity(intent)
}
if(history.size == 0 || history[history.size - 1] != uri) {
history.add(uri) //No double entries. Useful for reloading and going back //TODO: Make this comparison more reproducible
}
......@@ -23,6 +35,7 @@ class GeminiClient(applicationContext: Context, val mainContentView: TextView, v
val deferredResult = GlobalScope.async { connection.request(uri) }
GlobalScope.launch { responseHandler.handle(deferredResult) }
}
fun goToPage(uri: String) {
//TODO: Do checking and stuff
goToPage(URI.create(uri))
......
......@@ -19,7 +19,6 @@ class MainActivity : AppCompatActivity() {
private lateinit var geminiClient: GeminiClient
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
......@@ -30,7 +29,6 @@ class MainActivity : AppCompatActivity() {
uriField = findViewById(R.id.gemini_uri)
mainContentView = findViewById(R.id.mainContentView)
geminiClient = GeminiClient(
applicationContext,
mainContentView,
......@@ -45,7 +43,6 @@ class MainActivity : AppCompatActivity() {
uriField.clearFocus()
val inputService = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputService.hideSoftInputFromWindow(uriField.windowToken, 0)
}
uriField.setOnKeyListener { _, keyCode, event ->
......@@ -59,7 +56,12 @@ class MainActivity : AppCompatActivity() {
backButton.setOnClickListener {
geminiClient.goBack()
}
geminiClient.goToPage(getString(R.string.default_url))
geminiClient.sharedPreferences.getString("start_page_input", getString(R.string.default_url))?.let {
geminiClient.goToPage(
it
)
}
}
override fun onNewIntent(intent: Intent?) {
......
package rocks.ism.decentral.geminiclient
import android.R
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
class SettingsActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
supportFragmentManager.beginTransaction().replace(R.id.content, SettingsFragment()).commit()
}
}
package rocks.ism.decentral.geminiclient
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.preference.PreferenceFragmentCompat
class SettingsFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.preferences, rootKey)
}
}
......@@ -3,7 +3,8 @@
<string name="back_button_text">Back</string>
<string name="go_button_text">Go</string>
<string name="input_request_title">Input Request</string>
<string name="default_url">gemini://gus.guru/</string>
<string name="default_url">gemini://gemini.circumlunar.space/</string>
<string name="text_without_page_loaded">No Gemini page loaded yet</string>
<string name="uri_input_hint">URI of Gemini site to enter</string>
<string name="start_page_input_title">Start page</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<EditTextPreference
android:key="start_page_input"
android:selectAllOnFocus="true"
android:singleLine="true"
android:title="@string/start_page_input_title"
android:defaultValue="@string/default_url"/>
</PreferenceScreen>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment