-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #415 from SwissCovid/feature/summer-sleep
Feature/summer sleep
- Loading branch information
Showing
25 changed files
with
761 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
app/src/main/java/ch/admin/bag/dp3t/hibernate/HibernatingInfoFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package ch.admin.bag.dp3t.hibernate | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.core.view.isVisible | ||
import androidx.fragment.app.Fragment | ||
import androidx.fragment.app.viewModels | ||
import ch.admin.bag.dp3t.R | ||
import ch.admin.bag.dp3t.TabbarHostFragment | ||
import ch.admin.bag.dp3t.databinding.FragmentHibernatingInfoBinding | ||
import ch.admin.bag.dp3t.html.HtmlFragment | ||
import ch.admin.bag.dp3t.storage.SecureStorage | ||
import ch.admin.bag.dp3t.util.AssetUtil | ||
import ch.admin.bag.dp3t.util.UrlUtil | ||
|
||
class HibernatingInfoFragment : Fragment() { | ||
|
||
companion object { | ||
@JvmStatic | ||
fun newInstance() = HibernatingInfoFragment() | ||
} | ||
|
||
private val viewModel: HibernatingViewModel by viewModels() | ||
|
||
private val secureStorage by lazy { SecureStorage.getInstance(requireContext()) } | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | ||
return FragmentHibernatingInfoBinding.inflate(inflater).apply { | ||
|
||
toolbar.setOnMenuItemClickListener { | ||
showImpressum() | ||
true | ||
} | ||
|
||
val infoBoxModel = secureStorage.hibernatingInfoboxCollection?.getInfoBox(resources.getString(R.string.language_key)) | ||
|
||
viewModel.isHibernatingModeEnabled.observe(viewLifecycleOwner) { isHibernatingModeEnabled -> | ||
if (!isHibernatingModeEnabled) { | ||
showHomeFragment() | ||
} | ||
} | ||
|
||
infoBoxModel?.let { | ||
title.text = it.title | ||
text.text = it.msg | ||
linkGroup.isVisible = it.urlTitle != null | ||
linkText.text = it.urlTitle | ||
linkGroup.setOnClickListener { v -> UrlUtil.openUrl(requireContext(), it.url) } | ||
} | ||
|
||
}.root | ||
} | ||
|
||
private fun showHomeFragment() { | ||
requireActivity().supportFragmentManager.beginTransaction() | ||
.replace(R.id.main_fragment_container, TabbarHostFragment.newInstance()) | ||
.commit() | ||
} | ||
|
||
private fun showImpressum() { | ||
val htmlFragment = HtmlFragment.newInstance( | ||
R.string.menu_impressum, AssetUtil.getImpressumBaseUrl(context), | ||
AssetUtil.getImpressumHtml(context) | ||
) | ||
requireActivity().supportFragmentManager.beginTransaction() | ||
.setCustomAnimations( | ||
R.anim.slide_enter, | ||
R.anim.slide_exit, | ||
R.anim.slide_pop_enter, | ||
R.anim.slide_pop_exit | ||
) | ||
.replace(R.id.main_fragment_container, htmlFragment) | ||
.addToBackStack(HtmlFragment::class.java.canonicalName) | ||
.commit() | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
app/src/main/java/ch/admin/bag/dp3t/hibernate/HibernatingViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package ch.admin.bag.dp3t.hibernate | ||
|
||
import android.app.Application | ||
import androidx.lifecycle.AndroidViewModel | ||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.viewModelScope | ||
import ch.admin.bag.dp3t.MainApplication | ||
import ch.admin.bag.dp3t.checkin.networking.CrowdNotifierKeyLoadWorker | ||
import ch.admin.bag.dp3t.networking.ConfigWorker | ||
import ch.admin.bag.dp3t.networking.FakeWorker | ||
import ch.admin.bag.dp3t.storage.SecureStorage | ||
import ch.admin.bag.dp3t.util.NotificationRepeatWorker | ||
import kotlinx.coroutines.launch | ||
import org.dpppt.android.sdk.DP3T | ||
import org.dpppt.android.sdk.internal.logger.Logger | ||
|
||
class HibernatingViewModel(application: Application) : AndroidViewModel(application) { | ||
|
||
companion object { | ||
private val TAG = "HibernatingViewModel" | ||
|
||
} | ||
|
||
private val isHibernatingModeEnabledMutable = MutableLiveData<Boolean>() | ||
val isHibernatingModeEnabled: LiveData<Boolean> = isHibernatingModeEnabledMutable | ||
|
||
init { | ||
loadConfig() | ||
} | ||
|
||
|
||
private fun loadConfig() { | ||
viewModelScope.launch { | ||
try { | ||
ConfigWorker.loadConfig(getApplication()) | ||
if (SecureStorage.getInstance(getApplication()).isHibernating) { | ||
isHibernatingModeEnabledMutable.value = true | ||
} else { | ||
MainApplication.initDP3T(getApplication()) | ||
FakeWorker.safeStartFakeWorker(getApplication()) | ||
CrowdNotifierKeyLoadWorker.startKeyLoadWorker(getApplication()) | ||
NotificationRepeatWorker.startWorker(getApplication()) | ||
ConfigWorker.scheduleConfigWorkerIfOutdated(getApplication()) | ||
isHibernatingModeEnabledMutable.value = false | ||
} | ||
} catch (e: Exception) { | ||
Logger.e(TAG, "config request failed", e) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.