2019-04-20 05:29:45 +00:00
|
|
|
package code.name.monkey.retromusic.activities
|
2018-12-06 08:52:57 +00:00
|
|
|
|
|
|
|
import android.content.Intent
|
|
|
|
import android.content.pm.PackageManager
|
|
|
|
import android.net.Uri
|
|
|
|
import android.os.Bundle
|
2019-12-01 15:27:01 +00:00
|
|
|
import android.view.MenuItem
|
|
|
|
import android.view.View
|
2018-12-06 08:52:57 +00:00
|
|
|
import androidx.core.app.ShareCompat
|
2019-12-01 15:27:01 +00:00
|
|
|
import androidx.recyclerview.widget.DefaultItemAnimator
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
2020-04-24 18:11:14 +00:00
|
|
|
import code.name.monkey.retromusic.App
|
2018-12-06 08:52:57 +00:00
|
|
|
import code.name.monkey.retromusic.Constants.APP_INSTAGRAM_LINK
|
|
|
|
import code.name.monkey.retromusic.Constants.APP_TELEGRAM_LINK
|
|
|
|
import code.name.monkey.retromusic.Constants.APP_TWITTER_LINK
|
|
|
|
import code.name.monkey.retromusic.Constants.FAQ_LINK
|
|
|
|
import code.name.monkey.retromusic.Constants.GITHUB_PROJECT
|
2019-01-02 03:55:55 +00:00
|
|
|
import code.name.monkey.retromusic.Constants.PINTEREST
|
2018-12-06 08:52:57 +00:00
|
|
|
import code.name.monkey.retromusic.Constants.RATE_ON_GOOGLE_PLAY
|
|
|
|
import code.name.monkey.retromusic.Constants.TELEGRAM_CHANGE_LOG
|
|
|
|
import code.name.monkey.retromusic.Constants.TRANSLATE
|
|
|
|
import code.name.monkey.retromusic.R
|
2019-04-20 05:29:45 +00:00
|
|
|
import code.name.monkey.retromusic.activities.base.AbsBaseActivity
|
|
|
|
import code.name.monkey.retromusic.adapter.ContributorAdapter
|
2020-05-20 10:14:49 +00:00
|
|
|
import code.name.monkey.retromusic.extensions.applyToolbar
|
2019-05-22 03:03:19 +00:00
|
|
|
import code.name.monkey.retromusic.model.Contributor
|
2019-12-01 15:27:01 +00:00
|
|
|
import code.name.monkey.retromusic.util.NavigationUtil
|
2020-04-24 21:34:39 +00:00
|
|
|
import com.google.gson.Gson
|
|
|
|
import com.google.gson.reflect.TypeToken
|
2020-02-26 16:49:24 +00:00
|
|
|
import kotlinx.android.synthetic.main.activity_about.*
|
|
|
|
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.*
|
2020-04-24 21:34:39 +00:00
|
|
|
import java.io.IOException
|
|
|
|
import java.nio.charset.StandardCharsets
|
2018-12-06 08:52:57 +00:00
|
|
|
|
2020-04-24 21:34:39 +00:00
|
|
|
class AboutActivity : AbsBaseActivity(), View.OnClickListener {
|
2018-12-06 08:52:57 +00:00
|
|
|
|
2020-04-24 21:34:39 +00:00
|
|
|
private val contributorsJson: String?
|
2019-12-05 18:18:54 +00:00
|
|
|
get() {
|
|
|
|
val json: String
|
|
|
|
try {
|
2020-04-24 21:34:39 +00:00
|
|
|
val inputStream = assets.open("contributors.json")
|
2019-12-05 18:18:54 +00:00
|
|
|
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
|
|
|
|
}
|
2020-04-24 21:34:39 +00:00
|
|
|
|
2019-12-05 18:18:54 +00:00
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
setDrawUnderStatusBar()
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
setContentView(R.layout.activity_about)
|
|
|
|
setStatusbarColorAuto()
|
|
|
|
setNavigationbarColorAuto()
|
|
|
|
setLightNavigationBar(true)
|
|
|
|
|
2020-05-20 10:14:49 +00:00
|
|
|
applyToolbar(toolbar)
|
2019-12-05 18:18:54 +00:00
|
|
|
version.setSummary(getAppVersion())
|
|
|
|
setUpView()
|
2020-04-24 21:34:39 +00:00
|
|
|
loadContributors()
|
2019-12-05 18:18:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
|
|
|
if (item.itemId == android.R.id.home) {
|
|
|
|
onBackPressed()
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return super.onOptionsItemSelected(item)
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun openUrl(url: String) {
|
|
|
|
val i = Intent(Intent.ACTION_VIEW)
|
|
|
|
i.data = Uri.parse(url)
|
|
|
|
i.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
|
|
|
startActivity(i)
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun setUpView() {
|
|
|
|
appGithub.setOnClickListener(this)
|
|
|
|
faqLink.setOnClickListener(this)
|
|
|
|
telegramLink.setOnClickListener(this)
|
|
|
|
appRate.setOnClickListener(this)
|
|
|
|
appTranslation.setOnClickListener(this)
|
|
|
|
appShare.setOnClickListener(this)
|
|
|
|
donateLink.setOnClickListener(this)
|
|
|
|
instagramLink.setOnClickListener(this)
|
|
|
|
twitterLink.setOnClickListener(this)
|
|
|
|
changelog.setOnClickListener(this)
|
|
|
|
openSource.setOnClickListener(this)
|
|
|
|
pinterestLink.setOnClickListener(this)
|
|
|
|
bugReportLink.setOnClickListener(this)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onClick(view: View) {
|
|
|
|
when (view.id) {
|
|
|
|
R.id.pinterestLink -> openUrl(PINTEREST)
|
|
|
|
R.id.faqLink -> openUrl(FAQ_LINK)
|
|
|
|
R.id.telegramLink -> openUrl(APP_TELEGRAM_LINK)
|
|
|
|
R.id.appGithub -> openUrl(GITHUB_PROJECT)
|
|
|
|
R.id.appTranslation -> openUrl(TRANSLATE)
|
|
|
|
R.id.appRate -> openUrl(RATE_ON_GOOGLE_PLAY)
|
|
|
|
R.id.appShare -> shareApp()
|
|
|
|
R.id.donateLink -> NavigationUtil.goToSupportDevelopment(this)
|
|
|
|
R.id.instagramLink -> openUrl(APP_INSTAGRAM_LINK)
|
|
|
|
R.id.twitterLink -> openUrl(APP_TWITTER_LINK)
|
2020-04-30 20:48:14 +00:00
|
|
|
R.id.changelog -> openUrl(TELEGRAM_CHANGE_LOG)
|
2019-12-05 18:18:54 +00:00
|
|
|
R.id.openSource -> NavigationUtil.goToOpenSource(this)
|
|
|
|
R.id.bugReportLink -> NavigationUtil.bugReport(this)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun getAppVersion(): String {
|
|
|
|
return try {
|
2020-04-24 18:11:14 +00:00
|
|
|
val isPro = if (App.isProVersion()) "Pro" else "Free"
|
2019-12-05 18:18:54 +00:00
|
|
|
val packageInfo = packageManager.getPackageInfo(packageName, 0)
|
2020-04-24 18:11:14 +00:00
|
|
|
"${packageInfo.versionName} $isPro"
|
2019-12-05 18:18:54 +00:00
|
|
|
} catch (e: PackageManager.NameNotFoundException) {
|
|
|
|
e.printStackTrace()
|
|
|
|
"0.0.0"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun shareApp() {
|
|
|
|
ShareCompat.IntentBuilder.from(this).setType("text/plain")
|
2019-12-30 11:01:50 +00:00
|
|
|
.setChooserTitle(R.string.share_app)
|
|
|
|
.setText(String.format(getString(R.string.app_share), packageName)).startChooser()
|
2019-12-05 18:18:54 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 21:34:39 +00:00
|
|
|
private fun loadContributors() {
|
|
|
|
val type = object : TypeToken<List<Contributor>>() {
|
|
|
|
|
|
|
|
}.type
|
|
|
|
val contributors = Gson().fromJson<List<Contributor>>(contributorsJson, type)
|
|
|
|
|
|
|
|
val contributorAdapter = ContributorAdapter(contributors)
|
2019-12-05 18:18:54 +00:00
|
|
|
recyclerView.layoutManager = LinearLayoutManager(this)
|
|
|
|
recyclerView.itemAnimator = DefaultItemAnimator()
|
|
|
|
recyclerView.adapter = contributorAdapter
|
|
|
|
}
|
2018-12-06 08:52:57 +00:00
|
|
|
}
|