Skip to content

Commit

Permalink
[Fixed] Navigator circularTransform & ViewBinding issues with locked …
Browse files Browse the repository at this point in the history
…orientation
  • Loading branch information
KaustubhPatange committed Aug 6, 2021
1 parent 0f52d41 commit ea39063
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
android:value="ca-app-pub-1164424526503510~6985155768" />
<activity
android:name=".ui.activities.StartActivity"
android:screenOrientation="locked"
android:screenOrientation="portrait"
android:launchMode="singleTop"
android:theme="@style/StartTheme.Splash">
<intent-filter>
Expand Down Expand Up @@ -83,7 +83,7 @@
android:name=".cast.ui.ExpandedControlsActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
android:screenOrientation="locked"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.Dark.NoAction">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/kpstv/yts/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import androidx.core.content.edit
import androidx.fragment.app.Fragment
import androidx.preference.PreferenceManager
import com.kpstv.yts.AppSettings.VPN_ENABLED_PREF
import com.kpstv.yts.ui.helpers.ThemeHelper
import java.io.File

Expand Down Expand Up @@ -43,6 +44,9 @@ class AppPreference(context: Context) {

fun isVpnHelpShown(): Boolean = getBoolean(VPN_HELP_VIEW, false)
fun setVpnHelpShown(value: Boolean) = writeBoolean(VPN_HELP_VIEW, value)

fun isVPNEnabled(): Boolean = getBoolean(VPN_ENABLED_PREF, true)
fun setVPNEnabled(value: Boolean) = writeBoolean(VPN_ENABLED_PREF, value)
}

fun Context.defaultPreference() =
Expand Down Expand Up @@ -180,4 +184,6 @@ object AppSettings {

const val PREMIUM_PURCHASE_PREF = "premium_purchase_pref"
const val SHOW_DOWNLOAD_TIP_PREF = "show_download_tip_pref"

const val VPN_ENABLED_PREF = "enable_vpn"
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import com.kpstv.common_moviesy.extensions.viewBinding
import com.kpstv.navigation.FragmentNavigator
import com.kpstv.navigation.autoChildElevation
import com.kpstv.navigation.canFinish
import com.kpstv.yts.AppPreference
import com.kpstv.yts.BuildConfig
import com.kpstv.yts.cast.CastHelper
import com.kpstv.yts.data.db.localized.MainDao
import com.kpstv.yts.databinding.ActivityStartBinding
import com.kpstv.yts.defaultPreference
import com.kpstv.yts.extensions.utils.AppUtils
import com.kpstv.yts.ui.fragments.*
import com.kpstv.yts.ui.helpers.ActivityIntentHelper
Expand All @@ -39,6 +41,7 @@ class StartActivity : AppCompatActivity(), FragmentNavigator.Transmitter, Librar
private val castHelper = CastHelper()
private val mainCastHelper by lazy { MainCastHelper(this, lifecycle, castHelper) }
private val vpnHelper by lazy { VPNHelper(this) { navigator.show(it) } }
private val appPreference by defaultPreference()

private lateinit var navigator: FragmentNavigator

Expand Down Expand Up @@ -71,7 +74,8 @@ class StartActivity : AppCompatActivity(), FragmentNavigator.Transmitter, Librar
mainCastHelper.setUpCastRelatedStuff()
}

vpnHelper.initializeAndObserve()
if (appPreference.isVPNEnabled())
vpnHelper.initializeAndObserve()
/* registerFragmentLifecycleForLogging { fragment, state ->
if (BuildConfig.DEBUG) Log.e(fragment::class.simpleName, "=> $state")
}*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import androidx.preference.ListPreference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreferenceCompat
import com.kpstv.yts.AppInterface
import com.kpstv.yts.AppPreference
import com.kpstv.yts.AppSettings
import com.kpstv.yts.AppSettings.ANONYMOUS_TORRENT_DOWNLOAD_PREF
import com.kpstv.yts.AppSettings.TMDB_BASE_URL_PREF
import com.kpstv.yts.AppSettings.YIFY_BASE_URL_PREF
import com.kpstv.yts.AppSettings.YTS_BASE_URL_PREF
import com.kpstv.yts.R
import com.kpstv.yts.extensions.SearchType
import es.dmoral.toasty.Toasty

class GeneralSettingsFragment : PreferenceFragmentCompat() {
private val TAG = "GeneralSettingsFragment"
Expand Down Expand Up @@ -69,5 +72,10 @@ class GeneralSettingsFragment : PreferenceFragmentCompat() {
AppInterface.SUGGESTION_SEARCH_TYPE = SearchType.valueOf(value.toString())
true
}

findPreference<SwitchPreferenceCompat>(AppSettings.VPN_ENABLED_PREF)?.setOnPreferenceClickListener {
Toasty.info(requireContext(), getString(R.string.restart_app)).show()
true
}
}
}
13 changes: 13 additions & 0 deletions app/src/main/java/com/kpstv/yts/vpn/VPNHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ class VPNHelper(
}
}
}
// observe vpn state
lifecycleScope.launchWhenStarted {
vpnViewModel.vpnHelperState.collect { state ->
if (state is VpnHelperState.DisableVpn) {
preferences.setVpnHelpShown(false)
}
}
}

vpnViewModel.initialize()
}
Expand Down Expand Up @@ -218,4 +226,9 @@ sealed class VpnDialogUIState {
object Loading : VpnDialogUIState()
data class Detail(val vpnConfigurations: List<VpnConfiguration>) : VpnDialogUIState()
data class Connected(val ip: String) : VpnDialogUIState()
}

sealed class VpnHelperState {
object None : VpnHelperState()
object DisableVpn : VpnHelperState()
}
9 changes: 7 additions & 2 deletions app/src/main/java/com/kpstv/yts/vpn/VPNViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import org.json.JSONObject
Expand All @@ -27,6 +28,9 @@ class VPNViewModel @ViewModelInject constructor(
private val _showHover = MutableStateFlow(false)
val showHover: StateFlow<Boolean> = _showHover

private val _vpnHelperStateFlow : MutableStateFlow<VpnHelperState> = MutableStateFlow(VpnHelperState.None)
val vpnHelperState: StateFlow<VpnHelperState> = _vpnHelperStateFlow.asStateFlow()

private val _connectionStatus: MutableStateFlow<VpnConnectionStatus> =
MutableStateFlow(VpnConnectionStatus.LoadingConfiguration())
val connectionStatus: StateFlow<VpnConnectionStatus> = _connectionStatus
Expand Down Expand Up @@ -108,7 +112,7 @@ class VPNViewModel @ViewModelInject constructor(
_connectionDetails.tryEmit(detail)
}

private suspend fun initializeConfigs(): String? {
private suspend fun initializeConfigs() {
try {
val response = retrofitUtils.makeHttpCallAsync("http://ip-api.com/json")
if (response.isSuccessful) {
Expand All @@ -125,7 +129,6 @@ class VPNViewModel @ViewModelInject constructor(
} catch (e: Exception) {
e.printStackTrace()
}
return null
}


Expand All @@ -137,6 +140,8 @@ class VPNViewModel @ViewModelInject constructor(
AppDatabaseConverter.toAppDatabaseFromString(json)?.let { data ->
if (data.vpnAffectedCountries.contains(country)) {
_showHover.emit(true)
} else {
_vpnHelperStateFlow.tryEmit(VpnHelperState.DisableVpn)
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,7 @@
<string name="vpn_status_disconnect">VPN service will be stopped when the app is closed.</string>
<string name="gear_ad_text"><![CDATA[Need more fast & secure VPN servers?]]></string>
<string name="gear_ad_download">Download Gear VPN</string>
<string name="vpn_title">Enable VPN</string>
<string name="vpn_summary">Disable or enable built-in VPN to overcome YTS connection issues.</string>
<string name="restart_app">Restart the app to take the effect!</string>
</resources>
6 changes: 6 additions & 0 deletions app/src/main/res/xml/general_preference.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
app:summary="@string/anonymous_summary"
app:title="@string/anonymous_title" />

<SwitchPreferenceCompat
app:defaultValue="true"
app:key="enable_vpn"
app:summary="@string/vpn_summary"
app:title="@string/vpn_title" />

<PreferenceCategory app:title="App">
<SwitchPreferenceCompat
app:defaultValue="true"
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/LibraryDependency.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private object LibraryVersion {
const val AUTOBINDINGS = "1.1-alpha16"
const val APP_STARTUP = "1.0.0"
const val IMAGELOADERVIEW = "0.7-beta04"
const val NAVIGATOR = "0.1-alpha29"
const val NAVIGATOR = "0.1-alpha30"
const val NAVIGATOR_BOTTOM_NAVIGATION = "0.1-alpha18"
const val NAVIGATOR_TAB_NAVIGATION = "0.1-alpha12"
const val NAVIGATOR_EXTENSIONS = "0.6"
Expand Down

0 comments on commit ea39063

Please sign in to comment.