Bimba.git

commit d5571b89463fe58b9974a874a967ce5fe55f5420

Author: Adam <git@apiote.xyz>

configure feeds after first run

%!v(PANIC=String method: strings: negative Repeat count)


diff --git a/app/src/main/java/ml/adamsprogs/bimba/dashboard/MainActivity.kt b/app/src/main/java/ml/adamsprogs/bimba/dashboard/MainActivity.kt
index 8a6042c6b82b03ac27a0bcba0dcf901bfbe9fca1..c607543a5709f03412f59efca681844019bf36d2 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/dashboard/MainActivity.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/dashboard/MainActivity.kt
@@ -29,6 +29,8 @@ import ml.adamsprogs.bimba.dashboard.ui.home.HomeFragment
 import ml.adamsprogs.bimba.dashboard.ui.map.MapFragment
 import ml.adamsprogs.bimba.dashboard.ui.voyage.VoyageFragment
 import ml.adamsprogs.bimba.departures.DeparturesActivity
+import ml.adamsprogs.bimba.settings.ServerChooserActivity
+import ml.adamsprogs.bimba.settings.feeds.FeedChooserActivity
 
 
 class MainActivity : AppCompatActivity() {
@@ -56,6 +58,18 @@ 					super.onFragmentViewCreated(fm, f, v, savedInstanceState)
 				}
 			}, true
 		)
+
+		binding.navigationDrawer.setNavigationItemSelectedListener {
+			when (it.itemId) {
+				R.id.drawer_servers -> {
+					startActivity(Intent(this, ServerChooserActivity::class.java))
+				}
+				R.id.drawer_cities -> {
+					startActivity(Intent(this, FeedChooserActivity::class.java))
+				}
+			}
+			false
+		}
 
 		WindowCompat.setDecorFitsSystemWindows(window, false)
 		val navView: BottomNavigationView = binding.bottomNavigation




diff --git a/app/src/main/java/ml/adamsprogs/bimba/settings/ServerChooserActivity.kt b/app/src/main/java/ml/adamsprogs/bimba/settings/ServerChooserActivity.kt
index 9b66339ee929d6672d077cfdf83188b16f1e833b..99e6540ac6471b06e25eb5d5c1a85cc7b27a4ecc 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/settings/ServerChooserActivity.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/settings/ServerChooserActivity.kt
@@ -50,13 +50,20 @@
 		_binding = ActivityServerChooserBinding.inflate(layoutInflater)
 		setContentView(binding.root)
 
-		preferences.edit(true){
+		preferences.edit(true) {
 			putBoolean("inFeedsTransaction", true)
 		}
 
 		binding.button.isEnabled = false
 		binding.serverField.editText!!.addTextChangedListener { editable ->
 			binding.button.isEnabled = !editable.isNullOrBlank()
+		}
+
+		if (!preferences.getBoolean("firstRun", true)) {
+			Server.get(this).let { server ->
+				binding.serverField.editText!!.setText(server.host)
+				binding.tokenField.editText!!.setText(server.token)
+			}
 		}
 
 		binding.button.setOnClickListener {
@@ -107,7 +114,11 @@ 			}
 			if (response is FeedsSuccess) {
 				val token = preferences.getString("token", "")
 				if (response.rateLimited && token == "") {
-					showDialog(R.string.rate_limit, R.string.server_rate_limited_question, R.drawable.error_limit) {
+					showDialog(
+						R.string.rate_limit,
+						R.string.server_rate_limited_question,
+						R.drawable.error_limit
+					) {
 						runFeedsActivity()
 					}
 					return@launch




diff --git a/app/src/main/res/drawable/feeds_cities.xml b/app/src/main/res/drawable/feeds_cities.xml
new file mode 100644
index 0000000000000000000000000000000000000000..7324708d81054028bfebfd981910557dff919acb
--- /dev/null
+++ b/app/src/main/res/drawable/feeds_cities.xml
@@ -0,0 +1,5 @@
+<vector android:height="24dp" android:tint="#000000"
+    android:viewportHeight="24" android:viewportWidth="24"
+    android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
+    <path android:fillColor="@android:color/white" android:pathData="M15,11L15,5l-3,-3 -3,3v2L3,7v14h18L21,11h-6zM7,19L5,19v-2h2v2zM7,15L5,15v-2h2v2zM7,11L5,11L5,9h2v2zM13,19h-2v-2h2v2zM13,15h-2v-2h2v2zM13,11h-2L11,9h2v2zM13,7h-2L11,5h2v2zM19,19h-2v-2h2v2zM19,15h-2v-2h2v2z"/>
+</vector>




diff --git a/app/src/main/res/drawable/feeds_servers.xml b/app/src/main/res/drawable/feeds_servers.xml
new file mode 100644
index 0000000000000000000000000000000000000000..4a19b1b7c5a7d45a14c3fe2b89c426917130299b
--- /dev/null
+++ b/app/src/main/res/drawable/feeds_servers.xml
@@ -0,0 +1,5 @@
+<vector android:height="24dp" android:tint="#000000"
+    android:viewportHeight="24" android:viewportWidth="24"
+    android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
+    <path android:fillColor="@android:color/white" android:pathData="M20,13H4c-0.55,0 -1,0.45 -1,1v6c0,0.55 0.45,1 1,1h16c0.55,0 1,-0.45 1,-1v-6c0,-0.55 -0.45,-1 -1,-1zM7,19c-1.1,0 -2,-0.9 -2,-2s0.9,-2 2,-2 2,0.9 2,2 -0.9,2 -2,2zM20,3H4c-0.55,0 -1,0.45 -1,1v6c0,0.55 0.45,1 1,1h16c0.55,0 1,-0.45 1,-1V4c0,-0.55 -0.45,-1 -1,-1zM7,9c-1.1,0 -2,-0.9 -2,-2s0.9,-2 2,-2 2,0.9 2,2 -0.9,2 -2,2z"/>
+</vector>




diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index db6ee416fe2a78decde7397d7094bc2493116a1e..1d378b8e473132ec02ff62392656497537026224 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -48,12 +48,12 @@ 				app:menu="@menu/bottom_nav_menu" />
 		</androidx.constraintlayout.widget.ConstraintLayout>
 	</androidx.coordinatorlayout.widget.CoordinatorLayout>
 
-	<!-- todo show feeds and go to chooser (settings) -->
 	<com.google.android.material.navigation.NavigationView
 		android:id="@+id/navigation_drawer"
 		android:layout_width="wrap_content"
 		android:layout_height="match_parent"
-		android:layout_gravity="start" />
+		android:layout_gravity="start"
+		app:menu="@menu/drawer" />
 
 
 </androidx.drawerlayout.widget.DrawerLayout>
\ No newline at end of file




diff --git a/app/src/main/res/menu/drawer.xml b/app/src/main/res/menu/drawer.xml
new file mode 100644
index 0000000000000000000000000000000000000000..1b5fd35ca8d68a9c9a1937534cd1188ab25e7703
--- /dev/null
+++ b/app/src/main/res/menu/drawer.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+	<item
+		android:id="@+id/drawer_feeds"
+		android:title="@string/title_feeds">
+		<menu>
+			<item
+				android:id="@+id/drawer_servers"
+				android:checkable="true"
+				android:icon="@drawable/feeds_servers"
+				android:title="@string/title_servers" />
+			<item
+				android:id="@+id/drawer_cities"
+				android:checkable="true"
+				android:icon="@drawable/feeds_cities"
+				android:title="@string/title_cities" />
+		</menu>
+	</item>
+	<!-- other settings -->
+</menu>
\ No newline at end of file




diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 75a4074007c5cb20329c6d27d0e1f5ad5ba30960..c96a09b54dbf4154386909b6aafcb82956f88aad 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -79,4 +79,7 @@ 	Server is rate-limited
 	<string name="server_rate_limited_question">This server is rate-limited and no token was given. Do you want to continue?</string>
 	<string name="server_private_question">This server is private and no token was given</string>
 	<string name="last_update">Last update: %s</string>
+	<string name="title_feeds">Feeds</string>
+	<string name="title_servers">Servers</string>
+	<string name="title_cities">Cities</string>
 </resources>
\ No newline at end of file