fedilab-Android-App/app/src/main/java/fr/gouv/etalab/mastodon/activities/InstanceActivity.java

130 lines
5.3 KiB
Java
Raw Normal View History

/* Copyright 2017 Thomas Schneider
*
2017-07-10 10:33:24 +02:00
* This file is a part of Mastalab
*
* 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.
*
2017-07-10 10:33:24 +02:00
* Mastalab 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.
*
2017-08-04 11:11:27 +02:00
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
* see <http://www.gnu.org/licenses>. */
package fr.gouv.etalab.mastodon.activities;
import android.content.Intent;
2017-06-30 17:09:07 +02:00
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.text.Html;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import fr.gouv.etalab.mastodon.R;
import fr.gouv.etalab.mastodon.asynctasks.RetrieveInstanceAsyncTask;
import fr.gouv.etalab.mastodon.client.APIResponse;
import fr.gouv.etalab.mastodon.client.Entities.Instance;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveInstanceInterface;
2017-10-28 17:59:50 +02:00
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
/**
* Created by Thomas on 05/06/2017.
* Instance activity
*/
public class InstanceActivity extends AppCompatActivity implements OnRetrieveInstanceInterface {
private LinearLayout instance_container;
private RelativeLayout loader;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
2017-06-30 17:09:07 +02:00
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
2017-06-30 17:09:07 +02:00
if( theme == Helper.THEME_LIGHT){
setTheme(R.style.AppTheme);
}else {
setTheme(R.style.AppThemeDark);
}
if( getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.activity_instance);
2017-10-28 17:59:50 +02:00
changeDrawableColor(getApplicationContext(), R.drawable.ic_mail_outline,R.color.white);
2017-10-27 15:34:53 +02:00
instance_container = findViewById(R.id.instance_container);
loader = findViewById(R.id.loader);
instance_container.setVisibility(View.GONE);
loader.setVisibility(View.VISIBLE);
setTitle(getString(R.string.action_about_instance));
new RetrieveInstanceAsyncTask(getApplicationContext(), InstanceActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public void onRetrieveInstance(APIResponse apiResponse) {
instance_container.setVisibility(View.VISIBLE);
loader.setVisibility(View.GONE);
if( apiResponse.getError() != null){
Toast.makeText(getApplicationContext(), R.string.toast_error, Toast.LENGTH_LONG).show();
return;
}
final Instance instance = apiResponse.getInstance();
2017-10-27 15:34:53 +02:00
TextView instance_title = findViewById(R.id.instance_title);
TextView instance_description = findViewById(R.id.instance_description);
TextView instance_version = findViewById(R.id.instance_version);
TextView instance_uri = findViewById(R.id.instance_uri);
FloatingActionButton instance_contact = findViewById(R.id.instance_contact);
instance_title.setText(instance.getTitle());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
instance_description.setText(Html.fromHtml(instance.getDescription(), Html.FROM_HTML_MODE_LEGACY));
else
//noinspection deprecation
instance_description.setText(Html.fromHtml(instance.getDescription()));
if( instance.getDescription() == null || instance.getDescription().trim().length() == 0 )
instance_description.setText(getString(R.string.instance_no_description));
instance_version.setText(instance.getVersion());
instance_uri.setText(instance.getUri());
if( instance.getEmail() == null){
instance_contact.setVisibility(View.GONE);
}
instance_contact.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto",instance.getEmail(), null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "[Mastodon] - " + instance.getUri());
startActivity(Intent.createChooser(emailIntent, getString(R.string.send_email)));
}
});
}
}