Skip to content

Commit

Permalink
Merge branch 'master' into 4773-migrate-to-realm-kotlin-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
Okuro3499 authored Dec 18, 2024
2 parents 3f94d5f + d23d288 commit 31f96b6
Show file tree
Hide file tree
Showing 28 changed files with 182 additions and 55 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "org.ole.planet.myplanet"
minSdkVersion 26
targetSdkVersion 34
versionCode 2135
versionName "0.21.35"
versionCode 2142
versionName "0.21.42"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ abstract class BaseContainerFragment : BaseResourceFragment() {
val url = Utilities.getUrl(library)
if (!FileUtils.checkFileExist(url) && !TextUtils.isEmpty(url)) urls.add(url)
}
if (urls.isNotEmpty()) startDownload(urls) else Utilities.toast(
activity, getString(R.string.no_images_to_download)
)
if (urls.isNotEmpty()) startDownload(urls)
}
fun initRatingView(type: String?, id: String?, title: String?, listener: OnRatingChangeListener?) {
timesRated = requireView().findViewById(R.id.times_rated)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ abstract class BaseContainerFragment : BaseResourceFragment() {
val url = Utilities.getUrl(library)
if (!FileUtils.checkFileExist(url) && !TextUtils.isEmpty(url)) urls.add(url)
}
if (urls.isNotEmpty()) startDownload(urls) else Utilities.toast(
activity, getString(R.string.no_images_to_download)
)
if (urls.isNotEmpty()) startDownload(urls)
}
fun initRatingView(type: String?, id: String?, title: String?, listener: OnRatingChangeListener?) {
timesRated = requireView().findViewById(R.id.times_rated)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,9 @@ abstract class PermissionActivity : AppCompatActivity() {
permissions.add(Manifest.permission.READ_EXTERNAL_STORAGE)
}
}
if (permissions.isNotEmpty()) {
if (permissions.isNotEmpty() && !checkPermission(Manifest.permission.RECORD_AUDIO) &&!checkPermission(Manifest.permission.CAMERA)) {
val permissionsArray = permissions.toTypedArray<String>()
ActivityCompat.requestPermissions(this, permissionsArray, PERMISSION_REQUEST_CODE_FILE)
} else {
Toast.makeText(this, R.string.permissions_granted, Toast.LENGTH_SHORT).show()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,9 @@ abstract class PermissionActivity : AppCompatActivity() {
permissions.add(Manifest.permission.READ_EXTERNAL_STORAGE)
}
}
if (permissions.isNotEmpty()) {
if (permissions.isNotEmpty() && !checkPermission(Manifest.permission.RECORD_AUDIO) &&!checkPermission(Manifest.permission.CAMERA)) {
val permissionsArray = permissions.toTypedArray<String>()
ActivityCompat.requestPermissions(this, permissionsArray, PERMISSION_REQUEST_CODE_FILE)
} else {
Toast.makeText(this, R.string.permissions_granted, Toast.LENGTH_SHORT).show()
}
}

Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/org/ole/planet/myplanet/datamanager/Service.kt
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,12 @@ class Service(private val context: Context) {
name = JsonUtils.getString("name", jsonDoc)
parentDomain = JsonUtils.getString("parentDomain", jsonDoc)
registrationRequest = JsonUtils.getString("registrationRequest", jsonDoc)
}, {
realm.close()
callback.onSuccess("Server sync successfully")
}) { error: Throwable ->
realm.close()
error.printStackTrace()
}
copyToRealm(community)
}
Expand All @@ -321,6 +327,12 @@ class Service(private val context: Context) {
error.printStackTrace()
callback.onSuccess("Unable to connect to planet earth")
}


override fun onFailure(call: Call<JsonObject?>, t: Throwable) {
realm.close()
}
})
}

fun getMinApk(listener: ConfigurationIdListener?, url: String, pin: String, activity: SyncActivity) {
Expand Down
77 changes: 50 additions & 27 deletions app/src/main/java/org/ole/planet/myplanet/ui/SettingActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.ListView
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.ContextCompat
import androidx.preference.Preference
import androidx.preference.Preference.OnPreferenceChangeListener
Expand All @@ -23,6 +25,7 @@ import io.realm.Realm
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.ole.planet.myplanet.MainApplication.Companion.context
import org.ole.planet.myplanet.MainApplication.Companion.mRealm
import org.ole.planet.myplanet.MainApplication.Companion.setThemeMode
import org.ole.planet.myplanet.R
Expand Down Expand Up @@ -107,7 +110,7 @@ class SettingActivity : AppCompatActivity() {

val darkMode = findPreference<Preference>("dark_mode")
darkMode?.setOnPreferenceClickListener {
darkMode()
darkMode(requireActivity())
true
}

Expand Down Expand Up @@ -267,36 +270,56 @@ class SettingActivity : AppCompatActivity() {
dialog.show()
}

private fun darkMode() {
val options = arrayOf(getString(R.string.dark_mode_off), getString(R.string.dark_mode_on), getString(R.string.dark_mode_follow_system))
val currentMode = getCurrentThemeMode()
val checkedItem = when (currentMode) {
ThemeMode.LIGHT -> 0
ThemeMode.DARK -> 1
else -> 2
}
companion object {
fun darkMode(context: Context) {
val options = arrayOf(context.getString(R.string.dark_mode_off), context.getString(R.string.dark_mode_on),context.getString(R.string.dark_mode_follow_system))
val currentMode = getCurrentThemeMode(context)
val checkedItem = when (currentMode) {
ThemeMode.LIGHT -> 0
ThemeMode.DARK -> 1
else -> 2
}

val builder = AlertDialog.Builder(requireContext())
.setTitle(getString(R.string.select_theme_mode))
.setSingleChoiceItems(ArrayAdapter(requireContext(), R.layout.checked_list_item, options), checkedItem) { dialog, which ->
val selectedMode = when (which) {
0 -> ThemeMode.LIGHT
1 -> ThemeMode.DARK
2 -> ThemeMode.FOLLOW_SYSTEM
else -> ThemeMode.FOLLOW_SYSTEM
val builder = AlertDialog.Builder(context, R.style.CustomAlertDialogStyle)
.setTitle(context.getString(R.string.select_theme_mode))
.setSingleChoiceItems(ArrayAdapter(context, R.layout.checked_list_item, options), checkedItem) { dialog, which ->
val selectedMode = when (which) {
0 -> ThemeMode.LIGHT
1 -> ThemeMode.DARK
2 -> ThemeMode.FOLLOW_SYSTEM
else -> ThemeMode.FOLLOW_SYSTEM
}
setThemeMode(context, selectedMode)
dialog.dismiss()
}
setThemeMode(selectedMode)
dialog.dismiss()
}
.setNegativeButton(R.string.cancel, null)
.setNegativeButton(R.string.cancel, null)

val dialog = builder.create()
dialog.show()
}
val dialog = builder.create()
dialog.show()

private fun getCurrentThemeMode(): String {
val sharedPreferences = requireContext().getSharedPreferences(PREFS_NAME, MODE_PRIVATE)
return sharedPreferences.getString("theme_mode", ThemeMode.FOLLOW_SYSTEM) ?: ThemeMode.FOLLOW_SYSTEM
val window = dialog.window
window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
}

private fun getCurrentThemeMode(context: Context): String {
val sharedPreferences = context.getSharedPreferences(PREFS_NAME, MODE_PRIVATE)
return sharedPreferences.getString("theme_mode", ThemeMode.FOLLOW_SYSTEM) ?: ThemeMode.FOLLOW_SYSTEM
}

private fun setThemeMode(context: Context, themeMode: String) {
val sharedPreferences = context.getSharedPreferences(PREFS_NAME, MODE_PRIVATE)
with(sharedPreferences.edit()) {
putString("theme_mode", themeMode)
apply()
}
AppCompatDelegate.setDefaultNightMode(
when (themeMode) {
ThemeMode.LIGHT -> AppCompatDelegate.MODE_NIGHT_NO
ThemeMode.DARK -> AppCompatDelegate.MODE_NIGHT_YES
else -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
}
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ class AdapterResource(private val context: Context, private var libraryList: Lis
holder.bind()
holder.rowLibraryBinding.title.text = libraryList[position]?.title
setMarkdownText(holder.rowLibraryBinding.description, libraryList[position]?.description!!)
holder.rowLibraryBinding.description.setOnClickListener {
val library = libraryList[position]
openLibrary(library)
}
holder.rowLibraryBinding.timesRated.text = context.getString(R.string.num_total, libraryList[position]?.timesRated)
holder.rowLibraryBinding.checkbox.isChecked = selectedItems.contains(libraryList[position])
holder.rowLibraryBinding.checkbox.contentDescription = "${context.getString(R.string.selected)} ${libraryList[position]?.title}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ abstract class DashboardElementActivity : SyncActivity(), FragmentManager.OnBack
4 -> openEnterpriseFragment()
3 -> openCallFragment(TeamFragment(), "survey")
5 -> {
if (profileDbHandler.userModel?.isGuest() == true) {
showGuestUserDialog()
} else {
openCallFragment(CommunityTabFragment(), "community")
}
openCallFragment(CommunityTabFragment(), "community")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.ole.planet.myplanet.callback.SyncListener
import org.ole.planet.myplanet.databinding.*
import org.ole.planet.myplanet.datamanager.*
import org.ole.planet.myplanet.model.*
import org.ole.planet.myplanet.ui.SettingActivity
import org.ole.planet.myplanet.ui.community.HomeCommunityDialogFragment
import org.ole.planet.myplanet.ui.feedback.FeedbackFragment
import org.ole.planet.myplanet.ui.userprofile.*
Expand Down Expand Up @@ -110,6 +111,10 @@ class LoginActivity : SyncActivity(), TeamListAdapter.OnItemClickListener {
}
}
})
val selectDarkModeButton = findViewById<ImageButton>(R.id.themeToggleButton)
selectDarkModeButton?.setOnClickListener{
SettingActivity.SettingFragment.darkMode(this)
}
}

private fun declareElements() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class TeamFragment : Fragment(), AdapterTeamList.OnClickTeamItem {
fragmentTeamBinding.rvTeamList.adapter = adapterTeamList
listContentDescription(conditionApplied)
val itemCount = adapterTeamList.itemCount
showNoData(fragmentTeamBinding.tvMessage, itemCount, "teams")
showNoData(fragmentTeamBinding.tvMessage, itemCount, "$type")
if (itemCount == 0) {
fragmentTeamBinding.etSearch.visibility = View.GONE
fragmentTeamBinding.tableTitle.visibility = View.GONE
Expand Down
Binary file added app/src/main/res/drawable/moon_24dp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/moon_35.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/sun_24dp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/sun_35.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/white_moon_24dp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 14 additions & 1 deletion app/src/main/res/layout-large-land/activity_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,25 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageButton
android:id="@+id/themeToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:background="@null"
android:contentDescription="@string/select_theme_mode"
android:paddingStart="@dimen/_10dp"
android:paddingTop="6dp"
android:paddingEnd="@dimen/_10dp"
app:srcCompat="@drawable/sun_35"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/logoImageView"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center|top"
android:layout_marginTop="20dp"
android:layout_marginTop="110dp"
android:contentDescription="@string/ole_logo"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
18 changes: 15 additions & 3 deletions app/src/main/res/layout-night/activity_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,27 @@

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="40dp">
android:layout_height="match_parent">

<ImageButton
android:id="@+id/themeToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:background="@null"
android:contentDescription="@string/select_theme_mode"
android:paddingStart="@dimen/_10dp"
android:paddingTop="6dp"
android:paddingEnd="@dimen/_10dp"
app:srcCompat="@drawable/moon_35"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/logoImageView"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center|top"
android:layout_marginTop="20dp"
android:layout_marginTop="100dp"
android:contentDescription="@string/ole_logo"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
15 changes: 14 additions & 1 deletion app/src/main/res/layout-normal-land/activity_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,25 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageButton
android:id="@+id/themeToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:background="@null"
android:contentDescription="@string/select_theme_mode"
android:paddingStart="@dimen/_10dp"
android:paddingTop="6dp"
android:paddingEnd="@dimen/_10dp"
app:srcCompat="@drawable/sun_35"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/logoImageView"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center|top"
android:layout_marginTop="10dp"
android:layout_marginTop="110dp"
android:contentDescription="@string/ole_logo"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/layout-xlarge-land/activity_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,19 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageButton
android:id="@+id/themeToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:background="@null"
android:contentDescription="@string/select_theme_mode"
android:paddingStart="@dimen/_10dp"
android:paddingTop="6dp"
android:paddingEnd="@dimen/_10dp"
app:srcCompat="@drawable/sun_35"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/logoImageView"
android:layout_width="100dp"
Expand Down
18 changes: 15 additions & 3 deletions app/src/main/res/layout/activity_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,27 @@

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="40dp">
android:layout_height="match_parent">

<ImageButton
android:id="@+id/themeToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:background="@null"
android:contentDescription="@string/select_theme_mode"
android:paddingStart="@dimen/_10dp"
android:paddingTop="6dp"
android:paddingEnd="@dimen/_10dp"
app:srcCompat="@drawable/sun_35"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/logoImageView"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center|top"
android:layout_marginTop="20dp"
android:layout_marginTop="110dp"
android:contentDescription="@string/ole_logo"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
Loading

0 comments on commit 31f96b6

Please sign in to comment.