2017-04-16 04:05:25 +10:00
|
|
|
package com.keylesspalace.tusky;
|
|
|
|
|
2017-05-01 06:53:32 +10:00
|
|
|
import android.content.Intent;
|
2017-04-16 04:05:25 +10:00
|
|
|
import android.os.Bundle;
|
2018-03-28 04:47:00 +11:00
|
|
|
import android.support.annotation.NonNull;
|
2017-05-09 05:00:33 +10:00
|
|
|
import android.support.design.widget.Snackbar;
|
|
|
|
import android.support.v7.app.ActionBar;
|
2017-04-16 04:05:25 +10:00
|
|
|
import android.support.v7.widget.Toolbar;
|
2017-05-09 05:00:33 +10:00
|
|
|
import android.view.MenuItem;
|
2018-05-10 19:16:56 +10:00
|
|
|
import android.view.View;
|
2017-05-01 06:53:32 +10:00
|
|
|
import android.widget.Button;
|
2018-05-10 19:16:56 +10:00
|
|
|
import android.widget.ImageButton;
|
2017-04-16 04:05:25 +10:00
|
|
|
import android.widget.TextView;
|
|
|
|
|
2018-03-28 04:47:00 +11:00
|
|
|
import com.keylesspalace.tusky.di.Injectable;
|
2017-05-09 05:00:33 +10:00
|
|
|
import com.keylesspalace.tusky.entity.Account;
|
2018-03-28 04:47:00 +11:00
|
|
|
import com.keylesspalace.tusky.network.MastodonApi;
|
2017-05-09 05:00:33 +10:00
|
|
|
|
2018-05-10 19:16:56 +10:00
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.InputStreamReader;
|
2017-05-09 05:00:33 +10:00
|
|
|
import java.util.List;
|
|
|
|
|
2018-03-28 04:47:00 +11:00
|
|
|
import javax.inject.Inject;
|
|
|
|
|
2017-05-09 05:00:33 +10:00
|
|
|
import retrofit2.Call;
|
|
|
|
import retrofit2.Callback;
|
|
|
|
import retrofit2.Response;
|
|
|
|
|
2018-03-28 04:47:00 +11:00
|
|
|
public class AboutActivity extends BaseActivity implements Injectable {
|
2017-05-09 05:00:33 +10:00
|
|
|
private Button appAccountButton;
|
|
|
|
|
2018-03-28 04:47:00 +11:00
|
|
|
@Inject
|
|
|
|
public MastodonApi mastodonApi;
|
|
|
|
|
2017-04-16 04:05:25 +10:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_about);
|
2017-05-08 12:00:29 +10:00
|
|
|
|
2017-10-18 09:20:26 +11:00
|
|
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
2017-04-16 04:05:25 +10:00
|
|
|
setSupportActionBar(toolbar);
|
2017-10-28 22:39:32 +11:00
|
|
|
ActionBar actionBar = getSupportActionBar();
|
|
|
|
if (actionBar != null) {
|
|
|
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
|
|
|
actionBar.setDisplayShowHomeEnabled(true);
|
2017-05-09 05:00:33 +10:00
|
|
|
}
|
2017-04-16 04:05:25 +10:00
|
|
|
|
2017-10-28 22:39:32 +11:00
|
|
|
setTitle(R.string.about_title_activity);
|
|
|
|
|
2017-10-18 09:20:26 +11:00
|
|
|
TextView versionTextView = findViewById(R.id.versionTV);
|
2017-05-08 12:00:29 +10:00
|
|
|
String versionName = BuildConfig.VERSION_NAME;
|
2017-10-28 22:39:32 +11:00
|
|
|
String versionFormat = getString(R.string.about_tusky_version);
|
2017-05-08 12:00:29 +10:00
|
|
|
versionTextView.setText(String.format(versionFormat, versionName));
|
2017-05-09 05:00:33 +10:00
|
|
|
|
2017-10-18 09:20:26 +11:00
|
|
|
appAccountButton = findViewById(R.id.tusky_profile_button);
|
2018-03-28 04:47:00 +11:00
|
|
|
appAccountButton.setOnClickListener(v -> onAccountButtonClick());
|
2018-05-10 19:16:56 +10:00
|
|
|
setupAboutEmoji();
|
2017-04-16 04:05:25 +10:00
|
|
|
}
|
|
|
|
|
2017-05-09 05:00:33 +10:00
|
|
|
private void onAccountButtonClick() {
|
|
|
|
String appAccountId = getPrivatePreferences().getString("appAccountId", null);
|
|
|
|
if (appAccountId != null) {
|
|
|
|
viewAccount(appAccountId);
|
|
|
|
} else {
|
|
|
|
searchForAccountThenViewIt();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void viewAccount(String id) {
|
2017-05-01 06:53:32 +10:00
|
|
|
Intent intent = new Intent(this, AccountActivity.class);
|
2017-05-09 05:00:33 +10:00
|
|
|
intent.putExtra("id", id);
|
2017-05-01 06:53:32 +10:00
|
|
|
startActivity(intent);
|
|
|
|
}
|
2017-05-09 05:00:33 +10:00
|
|
|
|
|
|
|
private void searchForAccountThenViewIt() {
|
|
|
|
Callback<List<Account>> callback = new Callback<List<Account>>() {
|
|
|
|
@Override
|
2018-03-28 04:47:00 +11:00
|
|
|
public void onResponse(@NonNull Call<List<Account>> call, @NonNull Response<List<Account>> response) {
|
2017-05-09 05:00:33 +10:00
|
|
|
if (response.isSuccessful()) {
|
|
|
|
List<Account> accountList = response.body();
|
2018-03-28 04:47:00 +11:00
|
|
|
if (accountList != null && !accountList.isEmpty()) {
|
2018-03-03 23:24:03 +11:00
|
|
|
String id = accountList.get(0).getId();
|
2017-05-09 05:00:33 +10:00
|
|
|
getPrivatePreferences().edit()
|
|
|
|
.putString("appAccountId", id)
|
|
|
|
.apply();
|
|
|
|
viewAccount(id);
|
|
|
|
} else {
|
|
|
|
onSearchFailed();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
onSearchFailed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-03-28 04:47:00 +11:00
|
|
|
public void onFailure(@NonNull Call<List<Account>> call, @NonNull Throwable t) {
|
2017-05-09 05:00:33 +10:00
|
|
|
onSearchFailed();
|
|
|
|
}
|
|
|
|
};
|
2017-06-23 04:01:25 +10:00
|
|
|
mastodonApi.searchAccounts("Tusky@mastodon.social", true, null).enqueue(callback);
|
2017-05-09 05:00:33 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2018-05-10 19:16:56 +10:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-04-16 04:05:25 +10:00
|
|
|
}
|