Commit 8a6386ec authored by Ricki Hirner's avatar Ricki Hirner

Rework About activity

parent cb8b16e2
......@@ -25,6 +25,12 @@ android {
buildConfigField "String", "okhttpVersion", "\"$okhttp_version\""
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled true
......@@ -56,7 +62,7 @@ android {
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation project(':cert4android')
implementation project(':ical4android')
......@@ -70,6 +76,7 @@ dependencies {
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.jaredrummler:colorpicker:1.1.0'
implementation 'com.mikepenz:aboutlibraries:6.2.3'
implementation "com.squareup.okhttp3:okhttp:$okhttp_version"
implementation 'commons-io:commons-io:2.6'
}
......@@ -113,7 +113,6 @@
<activity
android:name=".ui.InfoActivity"
android:label="@string/activity_app_info"
android:theme="@style/AppTheme.NoActionBar"
android:parentActivityName=".ui.CalendarListActivity"/>
</application>
......
......@@ -8,63 +8,41 @@
package at.bitfire.icsdroid.ui
import android.annotation.SuppressLint
import android.app.Application
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.text.Html
import android.text.Spanned
import android.text.util.Linkify
import android.util.Log
import android.view.*
import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import at.bitfire.icsdroid.BuildConfig
import at.bitfire.icsdroid.Constants
import at.bitfire.icsdroid.HttpClient
import at.bitfire.icsdroid.R
import kotlinx.android.synthetic.main.app_info_activity.*
import kotlinx.android.synthetic.main.app_info_component.view.*
import org.apache.commons.io.IOUtils
import java.io.IOException
import java.nio.charset.StandardCharsets
import java.util.*
import kotlin.concurrent.thread
import com.mikepenz.aboutlibraries.LibsBuilder
class InfoActivity: AppCompatActivity() {
companion object {
val components = arrayOf(
arrayOf("ICSx⁵", "ICSx⁵/${BuildConfig.VERSION_NAME}", "Ricki Hirner, Bernhard Stockmann (bitfire.at)", "https://icsx5.bitfire.at", "gpl-3.0-standalone.html"),
arrayOf("Apache Commons", "Apache Commons", "Apache Software Foundation", "http://commons.apache.org/", "apache2.html"),
arrayOf("ColorPicker", "Color Picker", "Jared Rummler", "https://github.com/jaredrummler/ColorPicker", "mit.html"),
arrayOf("ical4j", "ical4j/${at.bitfire.ical4android.BuildConfig.version_ical4j}", "Ben Fortuna", "https://ical4j.github.io", "bsd-3clause.html")
)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.app_info_activity)
setSupportActionBar(toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
viewpager.adapter = TabsAdapter(supportFragmentManager)
tabs.setupWithViewPager(viewpager)
if (savedInstanceState == null)
ServiceLoader.load(StartupFragment::class.java).forEach { factory ->
factory.initialize(this)
if (savedInstanceState == null) {
val builder = LibsBuilder().apply {
aboutShowIcon = true
aboutAppName = getString(R.string.app_name)
aboutAppSpecial1 = getString(R.string.app_info_gplv3)
aboutAppSpecial1Description = getString(R.string.app_info_gplv3_note)
aboutAppSpecial2 = getString(R.string.app_info_donate)
aboutAppSpecial2Description = getString(R.string.donate_message) + "\n\n" +
"<a href=\"${DonateDialogFragment.donationUri}\">${getString(R.string.donate_now)}</a>"
aboutDescription = getString(R.string.app_info_description)
aboutVersionString = getString(R.string.app_info_version, BuildConfig.VERSION_NAME, BuildConfig.FLAVOR)
showLicense = true
}
builder.supportFragment()
supportFragmentManager.beginTransaction()
.replace(android.R.id.content, builder.supportFragment())
.commit()
}
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
......@@ -72,16 +50,6 @@ class InfoActivity: AppCompatActivity() {
return true
}
override fun onPause() {
super.onPause()
HttpClient.setForeground(false)
}
override fun onResume() {
super.onResume()
HttpClient.setForeground(true)
}
fun showWebSite(item: MenuItem) {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://icsx5.bitfire.at/?pk_campaign=icsx5-app&pk_kwd=info-activity")))
}
......@@ -90,87 +58,4 @@ class InfoActivity: AppCompatActivity() {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/icsx5app")))
}
class TabsAdapter(
fm: FragmentManager
): FragmentPagerAdapter(fm) {
override fun getCount() = components.size
override fun getPageTitle(position: Int) = components[position][0]
override fun getItem(position: Int) = ComponentFragment.instantiate(position)
}
class ComponentFragment: Fragment() {
companion object {
const val KEY_POSITION = "position"
fun instantiate(position: Int): ComponentFragment {
val frag = ComponentFragment()
val args = Bundle(1)
args.putInt(KEY_POSITION, position)
frag.arguments = args
return frag
}
}
@SuppressLint("SetTextI18n")
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
val info = components[arguments!!.getInt(KEY_POSITION)]
val v = inflater.inflate(R.layout.app_info_component, container, false)
v.title.text = info[1]
v.copyright.text = "© ${info[2]}"
v.url.autoLinkMask = Linkify.WEB_URLS
v.url.text = info[3]
// load and format license text
val model = ViewModelProviders.of(this).get(LicenseModel::class.java)
model.getHtml(info[4]).observe(this, Observer { formattedText ->
v.license.apply {
text = formattedText
autoLinkMask = Linkify.WEB_URLS
}
})
return v
}
}
class LicenseModel(
application: Application
): AndroidViewModel(application) {
fun getHtml(fileName: String) =
LicenseData(getApplication(), "license/$fileName")
}
class LicenseData(
context: Context,
fileName: String
): LiveData<Spanned>() {
init {
thread {
try {
context.resources.assets.open(fileName).use {
val html = IOUtils.toString(it, StandardCharsets.UTF_8)
postValue(Html.fromHtml(html))
}
} catch(e: IOException) {
Log.e(Constants.TAG, "Couldn't load license text", e)
}
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) Ricki Hirner (bitfire web engineering).
~ All rights reserved. This program and the accompanying materials
~ are made available under the terms of the GNU Public License v3.0
~ which accompanies this distribution, and is available at
~ http://www.gnu.org/licenses/gpl.html
-->
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
app:tabMode="scrollable"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.appbar.AppBarLayout >
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="define_colorpicker" translatable="false" />
<string name="library_colorpicker_author" translatable="false">Jared Rummler</string>
<string name="library_colorpicker_authorWebsite" translatable="false">https://jaredrummler.com/</string>
<string name="library_colorpicker_libraryName" translatable="false">Color Picker</string>
<string name="library_colorpicker_libraryDescription">A highly customizable color picker for Android</string>
<string name="library_colorpicker_libraryWebsite" translatable="false">https://github.com/jaredrummler/ColorPicker</string>
<string name="library_colorpicker_licenseId" translatable="false">mit</string>
<string name="library_colorpicker_isOpenSource" translatable="false">true</string>
</resources>
\ No newline at end of file
......@@ -9,6 +9,7 @@
<resources>
<string name="app_name" translatable="false">ICSx⁵</string>
<string name="account_name">Calendar subscriptions</string>
<string name="account_type" translatable="false">at.bitfire.icsdroid</string>
......@@ -78,6 +79,25 @@
</string-array>
<string name="activity_app_info">App info</string>
<string name="app_info_version">Version %1$s-%2$s</string>
<string name="app_info_gplv3" translatable="false">GPLv3</string>
<string name="app_info_gplv3_note"><![CDATA[
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <a href="https://www.gnu.org/licenses/">https://www.gnu.org/licenses/</a>.
]]></string>
<string name="app_info_donate">Donate</string>
<string name="app_info_description">Subscribe to Webcal feeds</string>
<string name="app_info_libraries">Libraries</string>
<string name="app_info_twitter">News &amp; updates</string>
<string name="app_info_web_site">Web site</string>
......
......@@ -8,7 +8,7 @@
buildscript {
ext.kotlin_version = '1.3.21'
ext.okhttp_version = '3.12.1'
ext.okhttp_version = '3.12.2'
repositories {
jcenter()
......
Subproject commit bd48ac822259554da19183d41949327b2ce46691
Subproject commit e4314588f8a42b302416aac6e324396ca857b597
Subproject commit 9c8b971961bce8594e2fecd516f17d302716714d
Subproject commit be40a3c7201b3d21a72fd1d67387a397ece572b7
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment