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;
|
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;
|
2017-05-01 06:53:32 +10:00
|
|
|
import android.view.View;
|
|
|
|
import android.widget.Button;
|
2017-04-16 04:05:25 +10:00
|
|
|
import android.widget.TextView;
|
|
|
|
|
2017-05-09 05:00:33 +10:00
|
|
|
import com.keylesspalace.tusky.entity.Account;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import retrofit2.Call;
|
|
|
|
import retrofit2.Callback;
|
|
|
|
import retrofit2.Response;
|
|
|
|
|
2017-05-08 12:00:29 +10:00
|
|
|
public class AboutActivity extends BaseActivity {
|
2017-05-09 05:00:33 +10:00
|
|
|
private Button appAccountButton;
|
|
|
|
|
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-04-16 04:05:25 +10:00
|
|
|
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
|
|
|
setSupportActionBar(toolbar);
|
2017-05-09 05:00:33 +10:00
|
|
|
ActionBar bar = getSupportActionBar();
|
|
|
|
if (bar != null) {
|
|
|
|
bar.setDisplayHomeAsUpEnabled(true);
|
|
|
|
bar.setDisplayShowHomeEnabled(true);
|
|
|
|
}
|
2017-04-16 04:05:25 +10:00
|
|
|
|
2017-05-08 12:00:29 +10:00
|
|
|
TextView versionTextView = (TextView) findViewById(R.id.versionTV);
|
|
|
|
String versionName = BuildConfig.VERSION_NAME;
|
|
|
|
String versionFormat = getString(R.string.about_application_version);
|
|
|
|
versionTextView.setText(String.format(versionFormat, versionName));
|
2017-05-09 05:00:33 +10:00
|
|
|
|
|
|
|
appAccountButton = (Button) findViewById(R.id.tusky_profile_button);
|
|
|
|
appAccountButton.setOnClickListener(new View.OnClickListener() {
|
2017-05-01 06:53:32 +10:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2017-05-09 05:00:33 +10:00
|
|
|
onAccountButtonClick();
|
2017-05-01 06:53:32 +10:00
|
|
|
}
|
|
|
|
});
|
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
|
|
|
|
public void onResponse(Call<List<Account>> call, Response<List<Account>> response) {
|
|
|
|
if (response.isSuccessful()) {
|
|
|
|
List<Account> accountList = response.body();
|
|
|
|
if (!accountList.isEmpty()) {
|
|
|
|
String id = accountList.get(0).id;
|
|
|
|
getPrivatePreferences().edit()
|
|
|
|
.putString("appAccountId", id)
|
|
|
|
.apply();
|
|
|
|
viewAccount(id);
|
|
|
|
} else {
|
|
|
|
onSearchFailed();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
onSearchFailed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Call<List<Account>> call, 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);
|
|
|
|
}
|
2017-04-16 04:05:25 +10:00
|
|
|
}
|