Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc Improvements #94

Merged
merged 7 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 35 additions & 34 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ android {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android.txt"),
"proguard-rules.pro"
"proguard-rules.pro",
)
}
}
Expand All @@ -38,7 +38,6 @@ android {
}
}


compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
Expand All @@ -59,40 +58,42 @@ android {

dependencies {

implementation("com.google.firebase:firebase-analytics-ktx:22.0.2")
implementation("com.onesignal:OneSignal:5.1.17")

implementation("androidx.appcompat:appcompat:1.7.0")
implementation("com.google.android.material:material:1.12.0")
implementation("androidx.recyclerview:recyclerview:1.3.2")
implementation("androidx.cardview:cardview:1.0.0")
implementation("androidx.core:core-ktx:1.13.1")
implementation("androidx.fragment:fragment-ktx:1.8.1")
implementation("androidx.viewpager2:viewpager2:1.1.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("com.google.android.flexbox:flexbox:3.0.0")
implementation("com.google.code.gson:gson:2.10.1")
implementation("com.squareup.okhttp3:okhttp:4.12.0")
implementation("com.squareup.retrofit2:retrofit:2.11.0")
implementation("com.squareup.retrofit2:converter-gson:2.9.0")

implementation("com.journeyapps:zxing-android-embedded:4.3.0")
// AndroidX
implementation(libs.androidx.appcompat)
implementation(libs.androidx.cardview)
implementation(libs.androidx.core)
implementation(libs.androidx.constraintlayout)
implementation(libs.androidx.fragment)
implementation(libs.androidx.viewmodel)
implementation(libs.androidx.livedata)
implementation(libs.androidx.recyclerview)
implementation(libs.androidx.viewpager2)

// Google
implementation(libs.google.material)
implementation(libs.google.flexbox)
implementation(libs.google.gson)
implementation(libs.google.firebase.analytics)

// Coil
implementation("io.coil-kt:coil:2.6.0")
implementation(libs.coil)

// Coroutines
val coroutinesVersion = "1.8.1"
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion")

// Lifecycle
val lifecycleVersion = "2.8.3"
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion")
implementation("androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion")

// Markwon
val markwonVersion = "4.6.2"
implementation("io.noties.markwon:core:$markwonVersion")
implementation("io.noties.markwon:linkify:$markwonVersion")
implementation(libs.kotlinx.coroutines.core)
implementation(libs.kotlinx.coroutines.android)

// MarkWon
implementation(libs.markwon.core)
implementation(libs.markwon.linkify)

// Okhttp
implementation(libs.squareup.okhttp)
implementation(libs.squareup.retrofit)
implementation(libs.squareup.converter.gson)

// OneSignal
implementation(libs.onesignal)

// Zxing
implementation(libs.zxing.android.embedded)
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<application
android:name=".CCIPApplication"
android:allowBackup="true"
android:enableOnBackInvokedCallback="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
Expand Down
18 changes: 2 additions & 16 deletions app/src/main/java/app/opass/ccip/model/LocalizedString.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package app.opass.ccip.model

import android.content.Context
import android.os.Build
import android.os.LocaleList
import androidx.annotation.RequiresApi

class LocalizedString {
companion object {
Expand Down Expand Up @@ -34,26 +32,14 @@ class LocalizedString {
if (translations.size == 0) return null

val keys = translations.keys.toList()
if (Build.VERSION.SDK_INT >= 24) {
localeListToStringList(context.resources.configuration.locales).firstOrNull(keys::contains)?.let {
return translations[it]
}
} else {
val locale = if (Build.VERSION.SDK_INT >= 24) {
context.resources.configuration.locales.get(0)
} else {
@Suppress("DEPRECATION")
context.resources.configuration.locale
}
val language = locale.language
if (translations.containsKey(language)) return translations[language]
localeListToStringList(context.resources.configuration.locales).firstOrNull(keys::contains)?.let {
return translations[it]
}

// No matches. Fallback to the first translation.
return translations[keys[0]]
}

@RequiresApi(24)
private fun localeListToStringList(localeList: LocaleList): Array<String> {
val list = mutableSetOf<String>()
for (i in 0 until localeList.size()) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/app/opass/ccip/model/Room.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app.opass.ccip.model

import android.content.Context
import app.opass.ccip.util.LocaleUtil
import java.util.*
import java.util.Locale

data class Room(
val id: String,
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/app/opass/ccip/model/Session.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package app.opass.ccip.model
import android.content.Context
import app.opass.ccip.util.LocaleUtil
import com.google.gson.annotations.SerializedName
import java.util.*
import java.util.Locale

data class Session(
val id: String,
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/app/opass/ccip/model/SessionLang.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app.opass.ccip.model

import android.content.Context
import app.opass.ccip.util.LocaleUtil
import java.util.*
import java.util.Locale

data class SessionLang(
val id: String,
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/app/opass/ccip/model/SessionTag.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app.opass.ccip.model

import android.content.Context
import app.opass.ccip.util.LocaleUtil
import java.util.*
import java.util.Locale

data class SessionTag(
val id: String,
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/app/opass/ccip/model/SessionType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app.opass.ccip.model

import android.content.Context
import app.opass.ccip.util.LocaleUtil
import java.util.*
import java.util.Locale

data class SessionType(
val id: String,
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/app/opass/ccip/model/Speaker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app.opass.ccip.model

import android.content.Context
import app.opass.ccip.util.LocaleUtil
import java.util.*
import java.util.Locale

data class Speaker(
val id: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
package app.opass.ccip.network.webclient

import android.annotation.TargetApi
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.webkit.WebResourceError
import android.webkit.WebResourceRequest
import android.webkit.WebView
import android.webkit.WebViewClient

class OfficialWebViewClient : WebViewClient() {
@Deprecated("Deprecated in Java")
override fun onReceivedError(view: WebView, errorCode: Int, description: String?, failingUrl: String?) {
super.onReceivedError(view, errorCode, description, failingUrl)
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) view.loadUrl("file:///android_asset/no_network.html")
}

@TargetApi(Build.VERSION_CODES.M)
override fun onReceivedError(view: WebView, request: WebResourceRequest, error: WebResourceError) {
super.onReceivedError(view, request, error)
if (request.isForMainFrame) view.loadUrl("file:///android_asset/no_network.html")
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/app/opass/ccip/ui/DrawerMenuAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import androidx.recyclerview.widget.RecyclerView.NO_POSITION
import app.opass.ccip.R
import app.opass.ccip.model.Feature
import app.opass.ccip.model.FeatureType
import app.opass.ccip.ui.DrawerMenuViewHolder.*
import app.opass.ccip.ui.DrawerMenuViewHolder.DividerViewHolder
import app.opass.ccip.ui.DrawerMenuViewHolder.MenuItemViewHolder
import app.opass.ccip.ui.DrawerMenuViewHolder.PlaceholderItemViewHolder
import coil.load

class DrawerMenuAdapter(
Expand Down
57 changes: 4 additions & 53 deletions app/src/main/java/app/opass/ccip/ui/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package app.opass.ccip.ui

import android.app.Activity
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Intent
import android.content.res.Configuration
import android.os.Bundle
Expand All @@ -12,11 +10,9 @@ import android.widget.ImageView
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.content.getSystemService
import androidx.core.net.toUri
import androidx.core.view.GravityCompat
import androidx.core.view.updatePadding
Expand All @@ -30,19 +26,17 @@ import app.opass.ccip.extension.setOnApplyWindowInsetsListenerCompat
import app.opass.ccip.extension.updateMargin
import app.opass.ccip.model.Feature
import app.opass.ccip.model.FeatureType
import app.opass.ccip.model.WifiNetworkInfo
import app.opass.ccip.network.PortalClient
import app.opass.ccip.ui.announcement.AnnouncementFragment
import app.opass.ccip.ui.event.EventActivity
import app.opass.ccip.ui.fastpass.FastPassFragment
import app.opass.ccip.ui.fastpass.MyTicketFragment
import app.opass.ccip.ui.schedule.ScheduleTabFragment
import app.opass.ccip.ui.wifi.WiFiNetworkFragment
import app.opass.ccip.util.CryptoUtil
import app.opass.ccip.util.PreferenceUtil
import app.opass.ccip.util.WifiUtil
import coil.load
import com.google.android.material.navigation.NavigationView
import com.google.android.material.snackbar.Snackbar
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
Expand Down Expand Up @@ -275,7 +269,9 @@ class MainActivity : AppCompatActivity(), CoroutineScope {
val feature = item.origFeature
if (item.shouldShowLaunchIcon) return this.startActivity(Intent(Intent.ACTION_VIEW, feature.url!!.toUri()))
if (feature.feature == FeatureType.WIFI) {
feature.wifiNetworks?.let(::showWifiDialog)
feature.wifiNetworks?.let {
WiFiNetworkFragment.show(it, supportFragmentManager)
}
mDrawerLayout.closeDrawers()
return
}
Expand Down Expand Up @@ -309,51 +305,6 @@ class MainActivity : AppCompatActivity(), CoroutineScope {
mDrawerLayout.closeDrawers()
}

private fun onWifiSelected(info: WifiNetworkInfo) {
val success = WifiUtil.installNetwork(this, info)
if (success) {
Snackbar
.make(mDrawerLayout, R.string.wifi_saved, Snackbar.LENGTH_SHORT)
.setAnchorView(navbarAnchor)
.show()
} else {
val hasPassword = !info.password.isNullOrEmpty()
if (!hasPassword) {
Snackbar
.make(mDrawerLayout, R.string.failed_to_save_wifi, Snackbar.LENGTH_LONG)
.setAnchorView(navbarAnchor)
.show()
return
}

getSystemService<ClipboardManager>()?.run {
setPrimaryClip(ClipData.newPlainText("", info.password))
} ?: return
Snackbar
.make(mDrawerLayout, R.string.failed_to_save_wifi_copied_to_clipboard, Snackbar.LENGTH_LONG)
.setAnchorView(navbarAnchor)
.show()
}
}

private fun showWifiDialog(networks: List<WifiNetworkInfo>) {
val dialog = AlertDialog.Builder(this).setTitle(R.string.choose_network_to_connect).create()
val rv = RecyclerView(this).apply {
layoutParams = RecyclerView.LayoutParams(
RecyclerView.LayoutParams.MATCH_PARENT,
RecyclerView.LayoutParams.MATCH_PARENT
)
layoutManager = LinearLayoutManager(this@MainActivity)
adapter = WifiNetworkAdapter(networks) { info ->
dialog.dismiss()
onWifiSelected(info)
}
}

dialog.setView(rv)
dialog.show()
}

private fun isFeatureValid(f: Feature) : Boolean {
return when (f.feature) {
FeatureType.FAST_PASS,
Expand Down
24 changes: 11 additions & 13 deletions app/src/main/java/app/opass/ccip/ui/PuzzleFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import android.Manifest
import android.annotation.SuppressLint
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.view.*
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.webkit.PermissionRequest
import android.webkit.WebSettings
import androidx.core.view.updatePadding
Expand Down Expand Up @@ -52,14 +56,10 @@ class PuzzleFragment : Fragment() {
webView.webViewClient = OfficialWebViewClient()
webView.webChromeClient = WebChromeViewClient(binding.progressBar, fun (request) {
if (!request!!.resources.contains(PermissionRequest.RESOURCE_VIDEO_CAPTURE)) request.deny()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Android M Permission check
if (mActivity.checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(arrayOf(Manifest.permission.CAMERA), 2)
request.deny()
} else {
request.grant(request.resources)
}
// Android M Permission check
if (mActivity.checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(arrayOf(Manifest.permission.CAMERA), 2)
request.deny()
} else {
request.grant(request.resources)
}
Expand All @@ -80,9 +80,7 @@ class PuzzleFragment : Fragment() {
val settings = webView.settings
settings.javaScriptEnabled = true
settings.domStorageEnabled = true
if (Build.VERSION.SDK_INT >= 21) {
settings.mixedContentMode = WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE
}
settings.mixedContentMode = WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE
}

override fun onDestroyView() {
Expand Down
Loading