Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Commit

Permalink
Reformating and code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
cyb3rko committed May 19, 2022
1 parent c8ad8f9 commit 267b783
Show file tree
Hide file tree
Showing 22 changed files with 584 additions and 205 deletions.
11 changes: 7 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,27 @@
android:theme="@style/Theme.AppSplash"
android:largeHeap="true"
android:name=".App">

<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan"
android:exported="true">

<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<meta-data android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />

</activity>

<activity android:name="com.mikepenz.aboutlibraries.ui.LibsActivity"
android:theme="@style/Theme.MaterialComponents.DayNight.NoActionBar" />
<activity android:name="com.cyb3rko.abouticons.IconInfoActivity"
android:theme="@style/Theme.MaterialComponents.DayNight.NoActionBar" />

<activity android:name=".appintro.MyAppIntro"
android:theme="@style/Theme.MaterialComponents.DayNight.NoActionBar"
android:screenOrientation="portrait" />
Expand All @@ -44,6 +46,7 @@
<meta-data
android:name="firebase_crashlytics_collection_enabled"
android:value="false" />

</application>

</manifest>
8 changes: 5 additions & 3 deletions app/src/main/java/com/cyb3rko/cavedroid/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ class App : Application() {

override fun onCreate() {
super.onCreate()
AppCompatDelegate.setDefaultNightMode(getSharedPreferences(SHARED_PREFERENCE, MODE_PRIVATE).getString(NIGHTMODE, AppCompatDelegate
.MODE_NIGHT_FOLLOW_SYSTEM.toString())!!.toInt())
AppCompatDelegate.setDefaultNightMode(getSharedPreferences(
SHARED_PREFERENCE,
MODE_PRIVATE
).getString(NIGHTMODE, AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM.toString())!!.toInt())
}
}
}
87 changes: 67 additions & 20 deletions app/src/main/java/com/cyb3rko/cavedroid/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ class MainActivity : AppCompatActivity() {
return
}

if (mySPR.getString(THEME, "0")!!.toInt() !in listOf(R.style.Theme_Cavedroid_Standard, R.style.Theme_Cavedroid_Green)) {
if (mySPR.getString(THEME, "0")!!.toInt() !in listOf(
R.style.Theme_Cavedroid_Standard,
R.style.Theme_Cavedroid_Green)
) {
mySPR.edit().putString(THEME, R.style.Theme_Cavedroid_Standard.toString()).commit()
}
setTheme(mySPR.getString(THEME, "0")!!.toInt())
Expand All @@ -81,8 +84,12 @@ class MainActivity : AppCompatActivity() {
navView.setupWithNavController(navController)

when (intent.action) {
"com.cyb3rko.cavedroid.searchshortcut" -> navController.navigate(R.id.navigation_notifications)
"com.cyb3rko.cavedroid.rankingsshortcut" -> navController.navigate(R.id.navigation_rankings)
"com.cyb3rko.cavedroid.searchshortcut" -> navController.navigate(
R.id.navigation_notifications
)
"com.cyb3rko.cavedroid.rankingsshortcut" -> navController.navigate(
R.id.navigation_rankings
)
}
}

Expand All @@ -106,10 +113,18 @@ class MainActivity : AppCompatActivity() {
if (token != "0") {
val kord = Kord(token)
val guild = kord.getGuild(Snowflake(195206438623248384))!!
val messageObject = (guild.getChannel(Snowflake(265060069194858496)) as MessageChannel).getLastMessage()!!
val messageObject = (guild.getChannel(
Snowflake(265060069194858496)
) as MessageChannel).getLastMessage()!!

if (force || messageObject.id.value.toLong() != sharedPreferences.getLong(LATEST_MESSAGE, 0)) {
showAnnouncementDialog(guild, messageObject, sharedPreferences, progressDialog)
if (force || messageObject.id.value.toLong() !=
sharedPreferences.getLong(LATEST_MESSAGE, 0)
) {
showAnnouncementDialog(
guild,
messageObject, sharedPreferences,
progressDialog
)
} else {
progressDialog?.cancel()
}
Expand All @@ -118,11 +133,17 @@ class MainActivity : AppCompatActivity() {
}
} catch (e: Exception) {
progressDialog?.cancel()
Toast.makeText(applicationContext, "Showing recent Announcement failed", Toast.LENGTH_SHORT).show()
Log.e("Cavedroid.MainActivity", "Reading and showing announcement failed: $e, ${e.message}")
Toast.makeText(
applicationContext,
"Showing recent Announcement failed",
Toast.LENGTH_SHORT
).show()
Log.e(
"Cavedroid.MainActivity",
"Reading and showing announcement failed: $e, ${e.message}"
)
}
}

}

private suspend fun showAnnouncementDialog(
Expand Down Expand Up @@ -168,8 +189,15 @@ class MainActivity : AppCompatActivity() {
message = "${substrings[0]}&%$name${substrings[1].drop(18)}"
} catch (e: Exception) {
message = message.replaceFirst("#", "&%")
Toast.makeText(applicationContext, "Showing recent Announcement failed", Toast.LENGTH_SHORT).show()
Log.e("Cavedroid.MainActivity", "Reading and showing announcement failed: $e, ${e.message}")
Toast.makeText(
applicationContext,
"Showing recent Announcement failed",
Toast.LENGTH_SHORT
).show()
Log.e(
"Cavedroid.MainActivity",
"Reading and showing announcement failed: $e, ${e.message}"
)
}
iterations++
}
Expand All @@ -188,7 +216,8 @@ class MainActivity : AppCompatActivity() {
if (endIndex == -1) {
endIndex = message.indexOf(":t)", index + 12)
}
message = message.substring(0 until index - 1) + message.substring(endIndex + 3)
message = message.substring(0 until index - 1) +
message.substring(endIndex + 3)
iterations++
}

Expand All @@ -206,28 +235,41 @@ class MainActivity : AppCompatActivity() {
val date = Date(time)
@SuppressLint("SimpleDateFormat")
val formattedDate = SimpleDateFormat("MM/dd/yyyy - HH:mm 'UTC'").format(date)
message = message.substring(0 until index) + formattedDate + message.substring(endIndex + 2)
message = message.substring(0 until index) +
formattedDate +
message.substring(endIndex + 2)
iterations++
}

message = message.replace("&%", "#")

runOnUiThread {
progressDialog?.cancel()
MaterialDialog(this@MainActivity, BottomSheet(LayoutMode.MATCH_PARENT)).show {
customView(viewRes = R.layout.announcement_dialog, scrollable = true, noVerticalPadding = true)
MaterialDialog(
this@MainActivity,
BottomSheet(LayoutMode.MATCH_PARENT)
).show {
customView(
viewRes = R.layout.announcement_dialog,
scrollable = true,
noVerticalPadding = true
)
onPreShow {
val view = it.getCustomView()
if (messageObject.attachments.isNotEmpty()) {
val drawable = messageObject.attachments.toList()[0]
if (sharedPreferences.getBoolean(ANNOUNCEMENT_IMAGE, true) && drawable.isImage) {
if (sharedPreferences.getBoolean(ANNOUNCEMENT_IMAGE, true) &&
drawable.isImage
) {
Glide.with(applicationContext)
.load(drawable.url)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(view.findViewById(R.id.image))
}
}
view.findViewById<TextView>(R.id.message).text = Html.fromHtml(Processor.process(message))
view.findViewById<TextView>(R.id.message).text = Html.fromHtml(
Processor.process(message)
)
}
}
}
Expand All @@ -237,7 +279,11 @@ class MainActivity : AppCompatActivity() {

private suspend fun reportAnnouncementError(message: Message) {
try {
Toast.makeText(applicationContext, "Showing recent Announcement failed", Toast.LENGTH_SHORT).show()
Toast.makeText(
applicationContext,
"Showing recent Announcement failed",
Toast.LENGTH_SHORT
).show()
val kord = Kord(Secrets().getAPIToken(packageName))
val channel = kord.getGuild(Snowflake(840366805649457172))
?.getChannel(Snowflake(933683219075838012))
Expand All @@ -254,12 +300,13 @@ class MainActivity : AppCompatActivity() {
}

override fun onBackPressed() {
val hostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment_activity_main)
val hostFragment = supportFragmentManager
.findFragmentById(R.id.nav_host_fragment_activity_main)
val fragment = hostFragment?.childFragmentManager?.fragments?.get(0)
if (fragment is ProfileCategoryFragment) {
fragment.returnToHome()
} else {
super.onBackPressed()
}
}
}
}
Loading

0 comments on commit 267b783

Please sign in to comment.