add License activity (#689)
* convert AboutActivity to Kotlin, use BottomSheetActivity for account resolving * improve AboutActivity * new License activity * fix filemojicompat url
This commit is contained in:
parent
570d7e3597
commit
3c569c6ac9
20 changed files with 605 additions and 546 deletions
|
@ -1,153 +0,0 @@
|
|||
package com.keylesspalace.tusky;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.keylesspalace.tusky.di.Injectable;
|
||||
import com.keylesspalace.tusky.entity.Account;
|
||||
import com.keylesspalace.tusky.network.MastodonApi;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class AboutActivity extends BaseActivity implements Injectable {
|
||||
private Button appAccountButton;
|
||||
|
||||
@Inject
|
||||
public MastodonApi mastodonApi;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_about);
|
||||
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setDisplayShowHomeEnabled(true);
|
||||
}
|
||||
|
||||
setTitle(R.string.about_title_activity);
|
||||
|
||||
TextView versionTextView = findViewById(R.id.versionTV);
|
||||
String versionName = BuildConfig.VERSION_NAME;
|
||||
String versionFormat = getString(R.string.about_tusky_version);
|
||||
versionTextView.setText(String.format(versionFormat, versionName));
|
||||
|
||||
appAccountButton = findViewById(R.id.tusky_profile_button);
|
||||
appAccountButton.setOnClickListener(v -> onAccountButtonClick());
|
||||
setupAboutEmoji();
|
||||
}
|
||||
|
||||
private void onAccountButtonClick() {
|
||||
String appAccountId = getPrivatePreferences().getString("appAccountId", null);
|
||||
if (appAccountId != null) {
|
||||
viewAccount(appAccountId);
|
||||
} else {
|
||||
searchForAccountThenViewIt();
|
||||
}
|
||||
}
|
||||
|
||||
private void viewAccount(String id) {
|
||||
Intent intent = AccountActivity.getIntent(this, id);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void searchForAccountThenViewIt() {
|
||||
Callback<List<Account>> callback = new Callback<List<Account>>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<List<Account>> call, @NonNull Response<List<Account>> response) {
|
||||
if (response.isSuccessful()) {
|
||||
List<Account> accountList = response.body();
|
||||
if (accountList != null && !accountList.isEmpty()) {
|
||||
String id = accountList.get(0).getId();
|
||||
getPrivatePreferences().edit()
|
||||
.putString("appAccountId", id)
|
||||
.apply();
|
||||
viewAccount(id);
|
||||
} else {
|
||||
onSearchFailed();
|
||||
}
|
||||
} else {
|
||||
onSearchFailed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<List<Account>> call, @NonNull Throwable t) {
|
||||
onSearchFailed();
|
||||
}
|
||||
};
|
||||
mastodonApi.searchAccounts("Tusky@mastodon.social", true, null).enqueue(callback);
|
||||
}
|
||||
|
||||
private void onSearchFailed() {
|
||||
Snackbar.make(appAccountButton, R.string.error_generic, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home: {
|
||||
onBackPressed();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private void setupAboutEmoji() {
|
||||
// Inflate the TextView containing the Apache 2.0 license text.
|
||||
TextView apacheView = findViewById(R.id.license_apache);
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
InputStream apacheLicense = getAssets().open("LICENSE_APACHE");
|
||||
StringBuilder builder = new StringBuilder();
|
||||
reader = new BufferedReader(
|
||||
new InputStreamReader(apacheLicense, "UTF-8"));
|
||||
String line;
|
||||
while((line = reader.readLine()) != null) {
|
||||
builder.append(line);
|
||||
builder.append('\n');
|
||||
}
|
||||
reader.close();
|
||||
apacheView.setText(builder);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Set up the button action
|
||||
ImageButton expand = findViewById(R.id.about_blobmoji_expand);
|
||||
expand.setOnClickListener(v ->
|
||||
{
|
||||
if(apacheView.getVisibility() == View.GONE) {
|
||||
apacheView.setVisibility(View.VISIBLE);
|
||||
((ImageButton) v).setImageResource(R.drawable.ic_arrow_drop_up_black_24dp);
|
||||
}
|
||||
else {
|
||||
apacheView.setVisibility(View.GONE);
|
||||
((ImageButton) v).setImageResource(R.drawable.ic_arrow_drop_down_black_24dp);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
87
app/src/main/java/com/keylesspalace/tusky/AboutActivity.kt
Normal file
87
app/src/main/java/com/keylesspalace/tusky/AboutActivity.kt
Normal file
|
@ -0,0 +1,87 @@
|
|||
package com.keylesspalace.tusky
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.support.annotation.StringRes
|
||||
import android.text.SpannableString
|
||||
import android.text.SpannableStringBuilder
|
||||
import android.text.method.LinkMovementMethod
|
||||
import android.text.style.URLSpan
|
||||
import android.text.util.Linkify
|
||||
import android.view.MenuItem
|
||||
import android.widget.TextView
|
||||
import com.keylesspalace.tusky.di.Injectable
|
||||
import com.keylesspalace.tusky.util.CustomURLSpan
|
||||
import kotlinx.android.synthetic.main.activity_about.*
|
||||
import kotlinx.android.synthetic.main.toolbar_basic.*
|
||||
|
||||
class AboutActivity : BottomSheetActivity(), Injectable {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_about)
|
||||
|
||||
setSupportActionBar(toolbar)
|
||||
supportActionBar?.run {
|
||||
setDisplayHomeAsUpEnabled(true)
|
||||
setDisplayShowHomeEnabled(true)
|
||||
}
|
||||
|
||||
setTitle(R.string.about_title_activity)
|
||||
|
||||
versionTextView.text = getString(R.string.about_tusky_version, BuildConfig.VERSION_NAME)
|
||||
|
||||
aboutLicenseInfoTextView.setClickableTextWithoutUnderlines(R.string.about_tusky_license)
|
||||
aboutWebsiteInfoTextView.setClickableTextWithoutUnderlines(R.string.about_project_site)
|
||||
aboutBugsFeaturesInfoTextView.setClickableTextWithoutUnderlines(R.string.about_bug_feature_request_site)
|
||||
|
||||
tuskyProfileButton.setOnClickListener {
|
||||
onAccountButtonClick()
|
||||
}
|
||||
|
||||
aboutLicensesButton.setOnClickListener {
|
||||
startActivity(Intent(this, LicenseActivity::class.java))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun onAccountButtonClick() {
|
||||
viewUrl("https://mastodon.social/@Tusky")
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
android.R.id.home -> {
|
||||
onBackPressed()
|
||||
return true
|
||||
}
|
||||
}
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun TextView.setClickableTextWithoutUnderlines(@StringRes textId: Int) {
|
||||
|
||||
val text = SpannableString(context.getText(textId))
|
||||
|
||||
Linkify.addLinks(text, Linkify.WEB_URLS)
|
||||
|
||||
val builder = SpannableStringBuilder(text)
|
||||
val urlSpans = text.getSpans(0, text.length, URLSpan::class.java)
|
||||
for (span in urlSpans) {
|
||||
val start = builder.getSpanStart(span)
|
||||
val end = builder.getSpanEnd(span)
|
||||
val flags = builder.getSpanFlags(span)
|
||||
|
||||
val customSpan = object : CustomURLSpan(span.url) {}
|
||||
|
||||
builder.removeSpan(span)
|
||||
builder.setSpan(customSpan, start, end, flags)
|
||||
}
|
||||
|
||||
setText(builder)
|
||||
linksClickable = true
|
||||
movementMethod = LinkMovementMethod.getInstance()
|
||||
|
||||
}
|
84
app/src/main/java/com/keylesspalace/tusky/LicenseActivity.kt
Normal file
84
app/src/main/java/com/keylesspalace/tusky/LicenseActivity.kt
Normal file
|
@ -0,0 +1,84 @@
|
|||
/* Copyright 2018 Conny Duck
|
||||
*
|
||||
* This file is a part of Tusky.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Tusky 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 Tusky; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
package com.keylesspalace.tusky
|
||||
|
||||
import android.os.Bundle
|
||||
import android.support.annotation.RawRes
|
||||
import android.util.Log
|
||||
import android.view.MenuItem
|
||||
import android.widget.TextView
|
||||
import com.keylesspalace.tusky.util.IOUtils
|
||||
import kotlinx.android.extensions.CacheImplementation
|
||||
import kotlinx.android.extensions.ContainerOptions
|
||||
import kotlinx.android.synthetic.main.activity_license.*
|
||||
import kotlinx.android.synthetic.main.toolbar_basic.*
|
||||
import java.io.BufferedReader
|
||||
import java.io.IOException
|
||||
import java.io.InputStreamReader
|
||||
|
||||
class LicenseActivity : BaseActivity() {
|
||||
|
||||
@ContainerOptions(cache = CacheImplementation.NO_CACHE)
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_license)
|
||||
|
||||
setSupportActionBar(toolbar)
|
||||
supportActionBar?.run {
|
||||
setDisplayHomeAsUpEnabled(true)
|
||||
setDisplayShowHomeEnabled(true)
|
||||
}
|
||||
|
||||
setTitle(R.string.title_licenses)
|
||||
|
||||
loadFileIntoTextView(R.raw.apache, licenseApacheTextView)
|
||||
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
android.R.id.home -> {
|
||||
onBackPressed()
|
||||
return true
|
||||
}
|
||||
}
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
private fun loadFileIntoTextView(@RawRes fileId: Int, textView: TextView) {
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
val br = BufferedReader(InputStreamReader(resources.openRawResource(fileId)))
|
||||
|
||||
try {
|
||||
var line: String? = br.readLine()
|
||||
while (line != null) {
|
||||
sb.append(line)
|
||||
sb.append('\n')
|
||||
line = br.readLine()
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
Log.w("LicenseActivity", e)
|
||||
}
|
||||
|
||||
IOUtils.closeQuietly(br)
|
||||
|
||||
textView.text = sb.toString()
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -86,4 +86,7 @@ abstract class ActivitiesModule {
|
|||
@ContributesAndroidInjector
|
||||
abstract fun contributesViewVideoActivity(): ViewVideoActivity
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract fun contributesLicenseActivity(): LicenseActivity
|
||||
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/* Copyright 2018 Conny Duck
|
||||
*
|
||||
* This file is a part of Tusky.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Tusky 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 Tusky; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
package com.keylesspalace.tusky.view
|
||||
|
||||
import android.content.Context
|
||||
import android.support.v7.widget.CardView
|
||||
import android.util.AttributeSet
|
||||
import com.keylesspalace.tusky.R
|
||||
import com.keylesspalace.tusky.util.LinkHelper
|
||||
import com.keylesspalace.tusky.util.ThemeUtils
|
||||
import com.keylesspalace.tusky.util.hide
|
||||
import kotlinx.android.synthetic.main.card_license.view.*
|
||||
|
||||
|
||||
class LicenseCard
|
||||
@JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0
|
||||
) : CardView(context, attrs, defStyleAttr) {
|
||||
|
||||
|
||||
init {
|
||||
inflate(context, R.layout.card_license, this)
|
||||
|
||||
setCardBackgroundColor(ThemeUtils.getColor(context, android.R.attr.colorBackground))
|
||||
|
||||
val a = context.theme.obtainStyledAttributes(attrs, R.styleable.LicenseCard, 0, 0)
|
||||
|
||||
val name: String? = a.getString(R.styleable.LicenseCard_name)
|
||||
val license: String? = a.getString(R.styleable.LicenseCard_license)
|
||||
val link: String? = a.getString(R.styleable.LicenseCard_link)
|
||||
a.recycle()
|
||||
|
||||
licenseCardName.text = name
|
||||
licenseCardLicense.text = license
|
||||
if(link.isNullOrBlank()) {
|
||||
licenseCardLink.hide()
|
||||
} else {
|
||||
licenseCardLink.text = link
|
||||
setOnClickListener { LinkHelper.openLink(link, context) }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue