Fix crashing on About on release build

This commit is contained in:
Hemanth S 2020-09-24 16:23:23 +05:30
parent 40da78af8b
commit 46dc5eb58e
9 changed files with 66 additions and 43 deletions

View file

@ -25,7 +25,7 @@ android {
}
signingConfigs {
release {
Properties properties = getProperties('/Users/apple/Documents/Github/retro.properties ')
Properties properties = getProperties('C:/Users/h4h13/Documents/GitHub/retro.properties ')
storeFile file(getProperty(properties, 'storeFile'))
keyAlias getProperty(properties, 'keyAlias')
storePassword getProperty(properties, 'storePassword')

View file

@ -3,24 +3,24 @@
"name": "Hemanth Savarala",
"summary": "Lead Developer & Designer",
"link": "https://github.com/h4h13",
"profile_image": "https://i.imgur.com/AoVs9oj.jpg"
"image": "https://i.imgur.com/AoVs9oj.jpg"
},
{
"name": "Lennart Glamann",
"summary": "Play Store banner and Images",
"link": "https://t.me/FlixbusLennart",
"profile_image": "https://i.imgur.com/Q5Nsx1R.jpg"
"image": "https://i.imgur.com/Q5Nsx1R.jpg"
},
{
"name": "Daksh P. Jain",
"summary": "Support Representative & Moderator",
"link": "https://daksh.eu.org",
"profile_image": "https://i.imgur.com/fnYpg65.jpg"
"image": "https://i.imgur.com/fnYpg65.jpg"
},
{
"name": "Milind Goel",
"summary": "Support Representative & Moderator",
"link": "https://t.me/MilindGoel15",
"profile_image": "https://i.imgur.com/Bz4De21_d.jpg"
"image": "https://i.imgur.com/Bz4De21_d.jpg"
}
]

View file

@ -108,6 +108,7 @@ private val dataModule = module {
get(),
get(),
get(),
get(),
get()
)
} bind Repository::class
@ -153,6 +154,9 @@ private val dataModule = module {
get()
)
}
single {
RealLocalDataRepository(get())
} bind LocalDataRepository::class
}
private val viewModules = module {

View file

@ -59,6 +59,11 @@ class ContributorAdapter(
return contributors.size
}
fun swapData(it: List<Contributor>) {
contributors = it
notifyDataSetChanged()
}
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val title: TextView = itemView.findViewById(R.id.title)
val text: TextView = itemView.findViewById(R.id.text)
@ -68,7 +73,7 @@ class ContributorAdapter(
title.text = contributor.name
text.text = contributor.summary
Glide.with(image.context)
.load(contributor.profileImage)
.load(contributor.image)
.error(R.drawable.ic_account)
.placeholder(R.drawable.ic_account)
.dontAnimate()

View file

@ -32,7 +32,6 @@ class LibraryViewModel(
private val legacyPlaylists = MutableLiveData<List<Playlist>>()
private val genres = MutableLiveData<List<Genre>>()
private val searchResults = MutableLiveData<List<Any>>()
val paletteColor: LiveData<Int> = _paletteColor
val panelState: MutableLiveData<NowPlayingPanelState> = MutableLiveData<NowPlayingPanelState>()
@ -293,6 +292,10 @@ class LibraryViewModel(
fun artist(artistId: Long): LiveData<Artist> = liveData {
emit(repository.artistById(artistId))
}
fun fetchContributors(): LiveData<List<Contributor>> = liveData {
emit(repository.contributor())
}
}
enum class ReloadType {

View file

@ -13,18 +13,17 @@ import code.name.monkey.retromusic.App
import code.name.monkey.retromusic.Constants
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.adapter.ContributorAdapter
import code.name.monkey.retromusic.model.Contributor
import code.name.monkey.retromusic.fragments.LibraryViewModel
import code.name.monkey.retromusic.util.NavigationUtil
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import kotlinx.android.synthetic.main.card_credit.*
import kotlinx.android.synthetic.main.card_other.*
import kotlinx.android.synthetic.main.card_retro_info.*
import kotlinx.android.synthetic.main.card_social.*
import java.io.IOException
import java.nio.charset.StandardCharsets
import org.koin.androidx.viewmodel.ext.android.sharedViewModel
class AboutFragment : Fragment(R.layout.fragment_about), View.OnClickListener {
private val libraryViewModel by sharedViewModel<LibraryViewModel>()
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
version.setSummary(getAppVersion())
@ -32,23 +31,6 @@ class AboutFragment : Fragment(R.layout.fragment_about), View.OnClickListener {
loadContributors()
}
private val contributorsJson: String?
get() {
val json: String
try {
val inputStream = requireActivity().assets.open("contributors.json")
val size = inputStream.available()
val buffer = ByteArray(size)
inputStream.read(buffer)
inputStream.close()
json = String(buffer, StandardCharsets.UTF_8)
} catch (ex: IOException) {
ex.printStackTrace()
return null
}
return json
}
private fun openUrl(url: String) {
val i = Intent(Intent.ACTION_VIEW)
@ -111,16 +93,14 @@ class AboutFragment : Fragment(R.layout.fragment_about), View.OnClickListener {
}
private fun loadContributors() {
val type = object : TypeToken<List<Contributor>>() {
}.type
val contributors = Gson().fromJson<List<Contributor>>(contributorsJson, type)
val contributorAdapter = ContributorAdapter(contributors)
val contributorAdapter = ContributorAdapter(emptyList())
recyclerView.apply {
layoutManager = LinearLayoutManager(requireContext())
itemAnimator = DefaultItemAnimator()
adapter = contributorAdapter
}
libraryViewModel.fetchContributors().observe(viewLifecycleOwner, { contributors ->
contributorAdapter.swapData(contributors)
})
}
}

View file

@ -14,12 +14,14 @@
package code.name.monkey.retromusic.model
import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import kotlinx.android.parcel.Parcelize
data class Contributor(
val name: String,
val summary: String,
val link: String,
@SerializedName("profile_image")
val profileImage: String
)
@Parcelize
class Contributor(
@SerializedName("name") val name: String = "",
@SerializedName("summary") val summary: String = "",
@SerializedName("link") val link: String = "",
@SerializedName("image") val image: String = ""
) : Parcelable

View file

@ -0,0 +1,25 @@
package code.name.monkey.retromusic.repository
import android.content.Context
import code.name.monkey.retromusic.model.Contributor
import com.google.gson.GsonBuilder
import com.google.gson.reflect.TypeToken
interface LocalDataRepository {
fun contributors(): List<Contributor>
}
class RealLocalDataRepository(
private val context: Context
) : LocalDataRepository {
override fun contributors(): List<Contributor> {
val jsonString = context.assets.open("contributors.json")
.bufferedReader().use { it.readText() }
val gsonBuilder = GsonBuilder()
val gson = gsonBuilder.create()
val listContributorType = object : TypeToken<List<Contributor>>() {}.type
return gson.fromJson(jsonString, listContributorType)
}
}

View file

@ -98,6 +98,7 @@ interface Repository {
suspend fun blackListPaths(): List<BlackListStoreEntity>
suspend fun lyrics(artist: String, title: String): Result<String>
suspend fun deleteSongs(songs: List<Song>)
suspend fun contributor(): List<Contributor>
}
class RealRepository(
@ -112,7 +113,8 @@ class RealRepository(
private val searchRepository: RealSearchRepository,
private val topPlayedRepository: TopPlayedRepository,
private val roomRepository: RoomRepository,
private val lyricsRestService: LyricsRestService
private val lyricsRestService: LyricsRestService,
private val localDataRepository: LocalDataRepository
) : Repository {
override suspend fun lyrics(artist: String, title: String): Result<String> = try {
@ -124,6 +126,8 @@ class RealRepository(
override suspend fun deleteSongs(songs: List<Song>) = roomRepository.deleteSongs(songs)
override suspend fun contributor(): List<Contributor> = localDataRepository.contributors()
override suspend fun fetchAlbums(): List<Album> = albumRepository.albums()
override suspend fun albumByIdAsync(albumId: Long): Album = albumRepository.album(albumId)