This commit is contained in:
Shabinder 2020-11-09 10:56:31 +05:30
parent c489c8c84a
commit ac423623e6
9 changed files with 34 additions and 37 deletions

View File

@ -123,7 +123,7 @@ dependencies {
implementation 'com.mpatric:mp3agic:0.9.1' implementation 'com.mpatric:mp3agic:0.9.1'
implementation 'com.shreyaspatil:EasyUpiPayment:3.0.0' implementation 'com.shreyaspatil:EasyUpiPayment:3.0.0'
implementation 'com.github.sealedtx:java-youtube-downloader:2.4.3' implementation 'com.github.sealedtx:java-youtube-downloader:2.4.4'
implementation "androidx.tonyodev.fetch2:xfetch2:3.1.5" implementation "androidx.tonyodev.fetch2:xfetch2:3.1.5"
implementation 'com.github.javiersantos:AppUpdater:2.7' implementation 'com.github.javiersantos:AppUpdater:2.7'

View File

@ -21,7 +21,6 @@ import android.Manifest
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.SharedPreferences
import android.net.Uri import android.net.Uri
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
@ -33,13 +32,14 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.app.AppCompatDelegate
import androidx.databinding.DataBindingUtil import androidx.databinding.DataBindingUtil
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import androidx.navigation.NavController
import androidx.navigation.findNavController
import com.github.javiersantos.appupdater.AppUpdater import com.github.javiersantos.appupdater.AppUpdater
import com.github.javiersantos.appupdater.enums.UpdateFrom import com.github.javiersantos.appupdater.enums.UpdateFrom
import com.shabinder.spotiflyer.databinding.MainActivityBinding import com.shabinder.spotiflyer.databinding.MainActivityBinding
import com.shabinder.spotiflyer.networking.SpotifyService import com.shabinder.spotiflyer.networking.SpotifyService
import com.shabinder.spotiflyer.networking.SpotifyServiceTokenRequest import com.shabinder.spotiflyer.networking.SpotifyServiceTokenRequest
import com.shabinder.spotiflyer.utils.NetworkInterceptor import com.shabinder.spotiflyer.utils.NetworkInterceptor
import com.shabinder.spotiflyer.utils.Provider.activity
import com.shabinder.spotiflyer.utils.createDirectories import com.shabinder.spotiflyer.utils.createDirectories
import com.shabinder.spotiflyer.utils.isOnline import com.shabinder.spotiflyer.utils.isOnline
import com.shabinder.spotiflyer.utils.startService import com.shabinder.spotiflyer.utils.startService
@ -53,25 +53,28 @@ import retrofit2.Retrofit
import retrofit2.converter.moshi.MoshiConverterFactory import retrofit2.converter.moshi.MoshiConverterFactory
import javax.inject.Inject import javax.inject.Inject
/*
* This is App's God Activity
* */
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
@AndroidEntryPoint @AndroidEntryPoint
class MainActivity : AppCompatActivity(){ class MainActivity : AppCompatActivity(){
private var spotifyService : SpotifyService? = null private var spotifyService : SpotifyService? = null
private var sharedPref :SharedPreferences? = null
private lateinit var binding: MainActivityBinding private lateinit var binding: MainActivityBinding
lateinit var snackBarAnchor: View lateinit var snackBarAnchor: View
private lateinit var sharedViewModel: SharedViewModel private lateinit var sharedViewModel: SharedViewModel
private lateinit var navController: NavController
@Inject lateinit var moshi: Moshi @Inject lateinit var moshi: Moshi
@Inject lateinit var spotifyServiceTokenRequest: SpotifyServiceTokenRequest @Inject lateinit var spotifyServiceTokenRequest: SpotifyServiceTokenRequest
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.main_activity) binding = DataBindingUtil.setContentView(this, R.layout.main_activity)
snackBarAnchor = binding.snackBarPosition
sharedViewModel = ViewModelProvider(this).get(SharedViewModel::class.java) sharedViewModel = ViewModelProvider(this).get(SharedViewModel::class.java)
navController = findNavController(R.id.navHostFragment)
snackBarAnchor = binding.snackBarPosition
//Enabling Dark Mode //Enabling Dark Mode
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
sharedPref = this.getPreferences(Context.MODE_PRIVATE)
authenticateSpotify() authenticateSpotify()
@ -89,7 +92,8 @@ class MainActivity : AppCompatActivity(){
override fun onNewIntent(intent: Intent?) { override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent) super.onNewIntent(intent)
Log.i("NEW INTENT", "Received") //Return to MainFragment For Further Processing of this Intent
navController.popBackStack(R.id.mainFragment,false)
handleIntentFromExternalActivity(intent) handleIntentFromExternalActivity(intent)
} }
@ -100,9 +104,10 @@ class MainActivity : AppCompatActivity(){
this.getSystemService(Context.POWER_SERVICE) as PowerManager this.getSystemService(Context.POWER_SERVICE) as PowerManager
val isIgnoringBatteryOptimizations = pm.isIgnoringBatteryOptimizations(packageName) val isIgnoringBatteryOptimizations = pm.isIgnoringBatteryOptimizations(packageName)
if (!isIgnoringBatteryOptimizations) { if (!isIgnoringBatteryOptimizations) {
val intent = Intent() val intent = Intent().apply{
intent.action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
intent.data = Uri.parse("package:$packageName") data = Uri.parse("package:$packageName")
}
startActivityForResult(intent, 1233) startActivityForResult(intent, 1233)
} }
} }
@ -188,6 +193,8 @@ class MainActivity : AppCompatActivity(){
.setUpdateFrom(UpdateFrom.XML) .setUpdateFrom(UpdateFrom.XML)
.setUpdateXML("https://raw.githubusercontent.com/Shabinder/SpotiFlyer/master/app/src/main/res/xml/app_update.xml") .setUpdateXML("https://raw.githubusercontent.com/Shabinder/SpotiFlyer/master/app/src/main/res/xml/app_update.xml")
.setCancelable(false) .setCancelable(false)
.setButtonDoNotShowAgain("Remind Later")
.setButtonDoNotShowAgainClickListener { dialog, _ -> dialog.dismiss() }
.setButtonUpdateClickListener { _, _ -> .setButtonUpdateClickListener { _, _ ->
val uri: Uri = val uri: Uri =
Uri.parse("http://github.com/Shabinder/SpotiFlyer/releases") Uri.parse("http://github.com/Shabinder/SpotiFlyer/releases")
@ -200,7 +207,12 @@ class MainActivity : AppCompatActivity(){
appUpdater.start() appUpdater.start()
} }
companion object{
private lateinit var instance: MainActivity
fun getInstance():MainActivity = instance
}
init { init {
activity = this instance = this
} }
} }

View File

@ -107,6 +107,9 @@ class MainFragment : Fragment() {
sharedViewModel.intentString.observe(viewLifecycleOwner,{ sharedViewModel.intentString.observe(viewLifecycleOwner,{
if(it != ""){ if(it != ""){
sharedViewModel.uiScope.launch(Dispatchers.IO) { sharedViewModel.uiScope.launch(Dispatchers.IO) {
//Wait for any Authentication to Finish ,
// this Wait prevents from multiple Authentication Requests
Thread.sleep(1000)
if(sharedViewModel.spotifyService.value == null){ if(sharedViewModel.spotifyService.value == null){
//Not Authenticated Yet //Not Authenticated Yet
Provider.activity.authenticateSpotify() Provider.activity.authenticateSpotify()

View File

@ -173,16 +173,6 @@ class SpotifyFragment : Fragment() {
*Live Data Observers *Live Data Observers
**/ **/
private fun initializeLiveDataObservers() { private fun initializeLiveDataObservers() {
/**
* CoverUrl Binding Observer!
**/
viewModel.coverUrl.observe(viewLifecycleOwner, {
if(it!="Loading") bindImage(binding.coverImage,it, Source.Spotify)
})
/**
* TrackList Binding Observer!
**/
viewModel.trackList.observe(viewLifecycleOwner, { viewModel.trackList.observe(viewLifecycleOwner, {
if (it.isNotEmpty()){ if (it.isNotEmpty()){
Log.i("SpotifyFragment","TrackList Updated") Log.i("SpotifyFragment","TrackList Updated")
@ -191,19 +181,12 @@ class SpotifyFragment : Fragment() {
} }
}) })
/** viewModel.coverUrl.observe(viewLifecycleOwner, {
* Title Binding Observer! if(it!="Loading") bindImage(binding.coverImage,it, Source.Spotify)
**/
viewModel.title.observe(viewLifecycleOwner, {
binding.titleView.text = it
}) })
sharedViewModel.intentString.observe(viewLifecycleOwner,{ viewModel.title.observe(viewLifecycleOwner, {
//Waiting for Authentication to Finish with Spotify()Access Token Observe binding.titleView.text = it
if(it != "" && it!=SpotifyFragmentArgs.fromBundle(requireArguments()).link){
//New Intent Received , Time TO RELOAD
(activity as MainActivity).onBackPressed()
}
}) })
} }
@ -215,7 +198,6 @@ class SpotifyFragment : Fragment() {
setImageResource(R.drawable.ic_tick) setImageResource(R.drawable.ic_tick)
visibility = View.VISIBLE visibility = View.VISIBLE
clearAnimation() clearAnimation()
keepScreenOn = false
} }
} }
} }

View File

@ -181,7 +181,6 @@ class YoutubeFragment : Fragment() {
setImageResource(R.drawable.ic_tick) setImageResource(R.drawable.ic_tick)
visibility = View.VISIBLE visibility = View.VISIBLE
clearAnimation() clearAnimation()
keepScreenOn = false
} }
} }
} }

View File

@ -49,7 +49,7 @@ import javax.inject.Singleton
@Module @Module
object Provider { object Provider {
lateinit var activity: MainActivity val activity: MainActivity = MainActivity.getInstance()
val defaultDir = Environment.DIRECTORY_MUSIC + File.separator + "SpotiFlyer" + File.separator val defaultDir = Environment.DIRECTORY_MUSIC + File.separator + "SpotiFlyer" + File.separator

View File

@ -20,6 +20,7 @@
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:background="@color/black"
android:layout_height="match_parent"> android:layout_height="match_parent">
<TextView <TextView
@ -43,6 +44,7 @@
<com.google.android.material.tabs.TabLayout <com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout" android:id="@+id/tabLayout"
android:background="@color/black"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"

View File

@ -38,7 +38,7 @@
app:layout_constraintStart_toStartOf="parent" /> app:layout_constraintStart_toStartOf="parent" />
<fragment <fragment
android:id="@+id/NavHostFragment" android:id="@+id/navHostFragment"
android:name="androidx.navigation.fragment.NavHostFragment" android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"

View File

@ -46,7 +46,6 @@
<com.google.android.material.floatingactionbutton.FloatingActionButton <com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/downloading_fab" android:id="@+id/downloading_fab"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:keepScreenOn="true"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:backgroundTint="@color/black" android:backgroundTint="@color/black"
android:scaleType="fitCenter" android:scaleType="fitCenter"