Skip to content

Commit

Permalink
feat: update about
Browse files Browse the repository at this point in the history
  • Loading branch information
ReChinX committed Oct 1, 2018
1 parent a7c6ba1 commit e25c49a
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 12 deletions.
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ android {
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
versionName "1.0.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
Expand Down Expand Up @@ -60,6 +60,7 @@ dependencies {
implementation 'me.drakeet.multitype:multitype:3.4.4'
implementation 'com.eclipsesource.j2v8:j2v8:4.8.2@aar'
implementation 'com.github.tbruyelle:rxpermissions:0.10.2'
implementation 'com.allenliu.versionchecklib:library:2.0.8'

implementation 'com.facebook.stetho:stetho:1.5.0'
implementation 'com.facebook.stetho:stetho-okhttp3:1.5.0'
Expand Down
73 changes: 62 additions & 11 deletions app/src/main/java/top/rechinx/meow/module/about/AboutActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@ package top.rechinx.meow.module.about

import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.os.PersistableBundle
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import butterknife.BindView
import butterknife.OnClick
import com.allenliu.versionchecklib.v2.AllenVersionChecker
import com.allenliu.versionchecklib.v2.builder.RequestVersionBuilder
import com.allenliu.versionchecklib.v2.builder.UIData
import com.allenliu.versionchecklib.v2.callback.RequestVersionListener
import me.drakeet.multitype.Items
import me.drakeet.support.about.AbsAboutActivity
import me.drakeet.support.about.Card
Expand All @@ -14,25 +22,68 @@ import me.drakeet.support.about.Contributor
import top.rechinx.meow.BuildConfig
import top.rechinx.meow.R
import me.drakeet.support.about.License
import org.json.JSONObject
import top.rechinx.meow.module.base.BaseActivity
import top.rechinx.meow.support.log.L


class AboutActivity: BaseActivity() {

class AboutActivity: AbsAboutActivity() {
@BindView(R.id.about_update_summary) lateinit var mUpdateText: TextView
@BindView(R.id.about_version_name) lateinit var mVersionName: TextView
@BindView(R.id.about_layout) lateinit var mLayoutView: View

override fun onItemsCreated(items: Items) {
items.add(Card("检查更新"))
items.add(Category("Developers"))
items.add(Contributor(R.mipmap.ic_launcher, "ReChinX", "Developer"))
items.add(Category("Open Source Licenses"))
items.add(License("about-page", "drakeet", License.APACHE_2, "https://github.com/drakeet/about-page"))
override fun initData() {
}

override fun onCreateHeader(icon: ImageView, slogan: TextView, version: TextView) {
icon.setImageResource(R.mipmap.ic_launcher_round)
slogan.text = "Meow"
version.text = "v${BuildConfig.VERSION_CODE}"
override fun initView() {
try {
val info = packageManager.getPackageInfo(packageName, 0)
mVersionName.text = "Version: ${info.versionName}"
} catch (e: Exception) {
e.printStackTrace()
}

}

@OnClick(R.id.about_resource_btn) fun onResourceClick() {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.about_resource_url)))
try {
startActivity(intent)
} catch (e: Exception) {
e.printStackTrace()
}
}

@OnClick(R.id.about_update_btn) fun onUpdateClick() {
mUpdateText.text = getString(R.string.request_version_checking)
AllenVersionChecker.getInstance()
.requestVersion()
.setRequestUrl("https://api.github.com/repos/ReChinX/Meow/releases/latest")
.request(object :RequestVersionBuilder(), RequestVersionListener {
override fun onRequestVersionSuccess(result: String?): UIData? {
val json = JSONObject(result)
if(json.getString("tag_name") == mVersionName.text) {
mUpdateText.text = getString(R.string.request_version_latest)
return null
}
mUpdateText.text = getString(R.string.request_version_latest)
return UIData.create().setDownloadUrl(json.getJSONArray("assets").getJSONObject(0).getString("browser_download_url"))
}

override fun onRequestVersionFailure(message: String?) {
mUpdateText.text = getString(R.string.request_version_error)
}

}).excuteMission(this)
}

override fun getLayoutId(): Int = R.layout.activity_about

override fun initPresenter() {
}


companion object {

fun createIntent(context: Context): Intent {
Expand Down
81 changes: 81 additions & 0 deletions app/src/main/res/layout/activity_about.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/about_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/custom_toolbar"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="?attr/colorPrimary">
<TextView
android:id="@+id/about_app_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:layout_marginBottom="10dp"
android:text="@string/app_name"
android:textColor="@color/white"
android:textSize="54sp"/>
<TextView
android:id="@+id/about_version_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/about_app_name"
android:layout_centerHorizontal="true"
android:textColor="@color/white"
android:textSize="14sp"/>
</RelativeLayout>
<LinearLayout
android:id="@+id/about_update_btn"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:padding="16dp"
android:clickable="true"
android:background="?android:attr/selectableItemBackground">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?android:attr/textColorPrimary"
android:textSize="16sp"
android:text="@string/about_update"/>
<TextView
android:id="@+id/about_update_summary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="2dp"
android:textSize="14sp"
android:text="@string/about_update_summary"/>
</LinearLayout>
<LinearLayout
android:id="@+id/about_resource_btn"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:padding="16dp"
android:clickable="true"
android:background="?android:attr/selectableItemBackground">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?android:attr/textColorPrimary"
android:textSize="16sp"
android:text="@string/about_resource"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="2dp"
android:textSize="14sp"
android:text="@string/about_resource_url"/>
</LinearLayout>
</LinearLayout>
</FrameLayout>
6 changes: 6 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,10 @@
<string name="pref_reader_mode_default">漫画默认配置</string>
<string name="pref_reader_mode_page">翻页模式</string>
<string name="pref_reader_mode_stream">卷纸模式</string>
<string name="about_update">检查更新</string>
<string name="about_update_summary">点击检查更新</string>
<string name="about_resource">源代码</string>
<string name="request_version_error">请求失败</string>
<string name="request_version_checking">检查更新中</string>
<string name="request_version_latest">已经是最新版本</string>
</resources>
7 changes: 7 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,11 @@
<string name="pref_reader_mode_default">Default</string>
<string name="pref_reader_mode_page">Page mode</string>
<string name="pref_reader_mode_stream">Scroll mode</string>
<string name="about_update">Check update</string>
<string name="about_update_summary">Click to check update</string>
<string name="about_resource">Source code</string>
<string name="about_resource_url">https://github.com/ReChinX/Meow</string>
<string name="request_version_error">Request version error</string>
<string name="request_version_checking">Checking version</string>
<string name="request_version_latest">Already latest version</string>
</resources>

0 comments on commit e25c49a

Please sign in to comment.