Skip to content

Commit

Permalink
Merge pull request #16 from PopStackHack/release/4.1.5
Browse files Browse the repository at this point in the history
Release/4.1.5
  • Loading branch information
vincent-paing authored Nov 5, 2020
2 parents c4f2def + c102274 commit ef7a52f
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package com.popstack.mvoter2015.feature.about

import android.annotation.SuppressLint
import android.content.Intent
import android.graphics.text.LineBreaker
import android.net.Uri
import android.os.Bundle
import android.text.Layout
import android.view.LayoutInflater
import androidx.lifecycle.lifecycleScope
import com.bluelinelabs.conductor.RouterTransaction
Expand All @@ -20,6 +18,7 @@ import com.popstack.mvoter2015.helper.conductor.requireActivity
import com.popstack.mvoter2015.helper.conductor.requireContext
import com.popstack.mvoter2015.helper.conductor.setSupportActionBar
import com.popstack.mvoter2015.helper.conductor.supportActionBar
import com.popstack.mvoter2015.helper.extensions.justify
import com.popstack.mvoter2015.logging.HasTag
import kotlinx.coroutines.launch
import javax.inject.Inject
Expand Down Expand Up @@ -78,13 +77,7 @@ class AboutController : LifeCycleAwareController<ControllerAboutBinding>(), Inje
openAppWebsite()
}

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
binding.tvCandidatePrivacyInstruction.justificationMode = LineBreaker.JUSTIFICATION_MODE_INTER_WORD
} else {
binding.tvCandidatePrivacyInstruction.justificationMode = Layout.JUSTIFICATION_MODE_INTER_WORD
}
}
binding.tvCandidatePrivacyInstruction.justify()

binding.tvVersion.text = requireContext().getString(R.string.version, BuildConfig.VERSION_NAME)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.popstack.mvoter2015.feature.candidate.listing

import android.annotation.SuppressLint
import android.graphics.text.LineBreaker
import android.os.Bundle
import android.text.Layout
import android.view.LayoutInflater
import android.view.View
import androidx.core.view.isVisible
Expand All @@ -20,10 +18,12 @@ import com.popstack.mvoter2015.feature.analytics.screen.ScreenTrackAnalyticsProv
import com.popstack.mvoter2015.feature.candidate.search.CandidateSearchController
import com.popstack.mvoter2015.feature.location.LocationUpdateController
import com.popstack.mvoter2015.helper.ConstituencyTab
import com.popstack.mvoter2015.helper.asyncviewstate.AsyncViewState
import com.popstack.mvoter2015.helper.conductor.requireActivity
import com.popstack.mvoter2015.helper.conductor.requireContext
import com.popstack.mvoter2015.helper.conductor.setSupportActionBar
import com.popstack.mvoter2015.helper.conductor.supportActionBar
import com.popstack.mvoter2015.helper.extensions.justify
import com.popstack.mvoter2015.logging.HasTag
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -57,8 +57,6 @@ class CandidateListController :

selectedTab = savedViewState?.getInt(VIEW_STATE_SELECTED_TAB)

viewModel.viewEventLiveData.observe(this, Observer(::observeViewEvent))

setSupportActionBar(binding.toolBar)
supportActionBar()?.title = requireContext().getString(R.string.title_candidates)

Expand Down Expand Up @@ -122,24 +120,46 @@ class CandidateListController :

CandidateListPagerParentRouter.setParentRouter(router)

showCandidatePrivacyInstructionIfNeeded()
viewModel.houseViewItemListResultLiveData.observe(this, Observer(::observeHouseViewItemListResult))

if (viewModel.houseViewItemListResultLiveData.value == null) {
viewModel.loadHouses()
}
}

viewModel.houseViewItemListLiveData.observe(lifecycleOwner, Observer(::observeHouseViewItem))
viewModel.loadHouses()
private fun observeHouseViewItemListResult(viewState: AsyncViewState<CandidateListViewModel.HouseViewItemListResult>) {
if (viewState is AsyncViewState.Loading) binding.progressIndicator.show()
else binding.progressIndicator.hide()

if (viewState is AsyncViewState.Success) {
val result = viewState.value
binding.tabLayout.isVisible = result is CandidateListViewModel.HouseViewItemListResult.HouseViewItemList
binding.viewPager.isVisible = result is CandidateListViewModel.HouseViewItemListResult.HouseViewItemList
binding.groupChooseCandidateComponent.isVisible = result is CandidateListViewModel.HouseViewItemListResult.RequestUserLocation
if (result is CandidateListViewModel.HouseViewItemListResult.HouseViewItemList) {
showCandidatePrivacyInstructionIfNeeded()
pagerAdapter.setItems(result.itemList)
binding.tabLayout.removeAllTabs()
result.itemList.forEach {
binding.tabLayout.addTab(
binding.tabLayout.newTab().setCustomView(
ConstituencyTab(requireActivity()).apply {
setText(it.houseName)
}
)
)
}
changeSelectedTabIfNeeded()
}
}
}

@Inject
lateinit var viewCache: CandidateListViewCache

@SuppressLint("WrongConstant")
private fun showCandidatePrivacyInstructionIfNeeded() {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
binding.tvCandidatePrivacyInstruction.justificationMode = LineBreaker.JUSTIFICATION_MODE_INTER_WORD
} else {
binding.tvCandidatePrivacyInstruction.justificationMode = Layout.JUSTIFICATION_MODE_INTER_WORD
}
}
binding.tvCandidatePrivacyInstruction.justify()

lifecycleScope.launch {
viewCache.shouldShowCandidatePrivacyInstruction().collectLatest {
Expand Down Expand Up @@ -178,29 +198,6 @@ class CandidateListController :
binding.viewPager.isVisible = false
}

private fun observeViewEvent(viewEvent: CandidateListViewModel.ViewEvent) {
if (viewEvent is CandidateListViewModel.ViewEvent.RequestUserLocation) {
binding.tabLayout.isVisible = false
binding.groupChooseCandidateComponent.isVisible = true
}
}

private fun observeHouseViewItem(houseViewItemList: List<CandidateListHouseViewItem>) {
binding.groupChooseCandidateComponent.isVisible = false
pagerAdapter.setItems(houseViewItemList)
binding.tabLayout.removeAllTabs()
houseViewItemList.forEach {
binding.tabLayout.addTab(
binding.tabLayout.newTab().setCustomView(
ConstituencyTab(requireActivity()).apply {
setText(it.houseName)
}
)
)
}
changeSelectedTabIfNeeded()
}

private fun changeSelectedTabIfNeeded() {
selectedTab?.let {
binding.viewPager.post {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,49 @@ package com.popstack.mvoter2015.feature.candidate.listing
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.popstack.mvoter2015.domain.constituency.model.HouseType
import com.popstack.mvoter2015.domain.location.usecase.GetUserStateRegion
import com.popstack.mvoter2015.domain.location.usecase.GetUserWard
import com.popstack.mvoter2015.helper.livedata.SingleLiveEvent
import com.popstack.mvoter2015.domain.location.usecase.UpdateWardDetails
import com.popstack.mvoter2015.helper.asyncviewstate.AsyncViewStateLiveData
import kotlinx.coroutines.launch
import javax.inject.Inject

class CandidateListViewModel @Inject constructor(
private val houseViewItemMapper: CandidateListHouseViewItemMapper,
private val getUserStateRegion: GetUserStateRegion,
private val updateWardDetails: UpdateWardDetails,
private val getUserWard: GetUserWard
) : ViewModel() {

sealed class ViewEvent {
object RequestUserLocation : ViewEvent()
}
sealed class HouseViewItemListResult {
object RequestUserLocation : HouseViewItemListResult()

val viewEventLiveData = SingleLiveEvent<ViewEvent>()
data class HouseViewItemList(
val itemList: List<CandidateListHouseViewItem>
) : HouseViewItemListResult()
}

val houseViewItemListLiveData =
SingleLiveEvent<List<CandidateListHouseViewItem>>()
val houseViewItemListResultLiveData =
AsyncViewStateLiveData<HouseViewItemListResult>()

fun loadHouses() {
viewModelScope.launch {
val houseTypes = HouseType.values()

val userWard = getUserWard.execute(Unit) ?: run {
viewEventLiveData.postValue(ViewEvent.RequestUserLocation)
houseViewItemListResultLiveData.postSuccess(HouseViewItemListResult.RequestUserLocation)
return@launch
}
val viewItems = houseTypes.map { houseType ->
houseViewItemMapper.mapFromHouseType(houseType, userWard)

houseViewItemListResultLiveData.postLoading()

try {
updateWardDetails.execute(Unit)
} catch (exception: Exception) {
//Ignore exception, allow update to fail
} finally {
val houseTypes = HouseType.values()
val viewItems = houseTypes.map { houseType ->
houseViewItemMapper.mapFromHouseType(houseType, userWard)
}
houseViewItemListResultLiveData.postSuccess(HouseViewItemListResult.HouseViewItemList(viewItems))
}
houseViewItemListLiveData.postValue(viewItems)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import androidx.core.view.isVisible
import androidx.lifecycle.Observer
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.bluelinelabs.conductor.RouterTransaction
Expand All @@ -21,6 +22,8 @@ import com.popstack.mvoter2015.helper.conductor.requireContext
import com.popstack.mvoter2015.helper.extensions.isLandScape
import com.popstack.mvoter2015.helper.extensions.isTablet
import com.popstack.mvoter2015.logging.HasTag
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

class LowerHouseCandidateListController : MvvmController<ControllerLowerHouseCandidateListBinding>(), HasTag {

Expand Down Expand Up @@ -65,7 +68,7 @@ class LowerHouseCandidateListController : MvvmController<ControllerLowerHouseCan
}

if (viewModel.viewItemLiveData.value == null) {
loadCandidates()
loadCandidates()
}
}

Expand All @@ -83,7 +86,6 @@ class LowerHouseCandidateListController : MvvmController<ControllerLowerHouseCan

private fun observeViewItem(viewState: AsyncViewState<CandidateListResult>) = with(binding) {
progressBar.isVisible = viewState is AsyncViewState.Loading
rvCandidate.isVisible = viewState is AsyncViewState.Success
tvErrorMessage.isVisible = viewState is AsyncViewState.Error
btnRetry.isVisible = viewState is AsyncViewState.Error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ class RegionalHouseCandidateListController() : MvvmController<ControllerRegional

private fun observeViewItem(viewState: AsyncViewState<CandidateListResult>) = with(binding) {
progressBar.isVisible = viewState is AsyncViewState.Loading
rvCandidate.isVisible = viewState is AsyncViewState.Success
tvErrorMessage.isVisible = viewState is AsyncViewState.Error
btnRetry.isVisible = viewState is AsyncViewState.Error
groupRemark.isVisible = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class UpperHouseCandidateListController : MvvmController<ControllerUpperHouseCan

private fun observeViewItem(viewState: AsyncViewState<CandidateListResult>) = with(binding) {
progressBar.isVisible = viewState is AsyncViewState.Loading
rvCandidate.isVisible = viewState is AsyncViewState.Success
tvErrorMessage.isVisible = viewState is AsyncViewState.Error
btnRetry.isVisible = viewState is AsyncViewState.Error

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.popstack.mvoter2015.helper.extensions

import android.annotation.SuppressLint
import android.graphics.drawable.Drawable
import android.text.Layout
import android.widget.TextView

fun TextView.setCompoundDrawablesKt(
Expand All @@ -19,4 +21,11 @@ fun TextView.setCompoundDrawableWithIntrinsicBoundsKt(
bottom: Drawable? = null
) {
this.setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, end, bottom)
}

@SuppressLint("WrongConstant")
fun TextView.justify() {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
justificationMode = Layout.JUSTIFICATION_MODE_INTER_WORD
}
}
22 changes: 17 additions & 5 deletions app/src/main/res/layout/controller_candidate_list.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:animateLayoutChanges="true">

<com.google.android.material.appbar.AppBarLayout
Expand Down Expand Up @@ -50,6 +50,19 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.google.android.material.progressindicator.ProgressIndicator
android:id="@+id/progressIndicator"
style="@style/Widget.MaterialComponents.ProgressIndicator.Linear.Indeterminate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
app:indicatorColor="@color/accent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:minHideDelay="500"
tools:visibility="visible" />

<ImageView
android:id="@+id/ivCandidateIndicator"
android:layout_width="100dp"
Expand Down Expand Up @@ -117,10 +130,10 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:visibility="gone"
tools:visibility="visible"
android:layout_marginBottom="-8dp"
app:cardBackgroundColor="@color/accent">
android:visibility="gone"
app:cardBackgroundColor="@color/accent"
tools:visibility="visible">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
Expand Down Expand Up @@ -156,5 +169,4 @@

</com.google.android.material.card.MaterialCardView>


</androidx.coordinatorlayout.widget.CoordinatorLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
android:layout_height="0dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvConstituencyName" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
android:layout_height="0dp"
android:clipToPadding="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
android:layout_height="0dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvConstituencyName" />

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/item_party_header.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
android:layout_height="12dp"
android:layout_gravity="center"
android:src="@drawable/ic_flag_24"
app:tint="@color/accent_20" />
app:tint="@android:color/white" />

</FrameLayout>

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<string name="badge_is_elected">အနိုင်ရ</string>

<!-- Party-->
<string name="header_total_party_count">(၂၀၂၀) ပြည့်နှစ် အထွေထွေရွေးကောက်ပွဲတွင် ဝင်ရောက်ယှဉ်ပြိုင်မည့် နိုင်ငံရေးပါတီ (၉၂) ခု</string>
<string name="header_total_party_count">(၂၀၂၀) ပြည့်နှစ် အထွေထွေရွေးကောက်ပွဲတွင် ဝင်ရောက်ယှဉ်ပြိုင်မည့် နိုင်ငံရေးပါတီ (၉၁) ခု</string>

<string name="policy">ပါတီ မူဝါဒ</string>
<string name="party_flag">ပါတီအလံ</string>
Expand Down
Loading

0 comments on commit ef7a52f

Please sign in to comment.