diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 99898a6d1..649c0d926 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -175,6 +175,11 @@ android:configChanges="orientation|screenSize" android:label="@string/app_name" /> + . */ +package fr.gouv.etalab.mastodon.activities; + +import android.content.Intent; +import android.content.SharedPreferences; +import android.net.Uri; +import android.os.AsyncTask; +import android.os.Bundle; +import android.text.method.LinkMovementMethod; +import android.view.MenuItem; +import android.view.View; +import android.widget.ImageView; +import android.widget.TextView; +import android.widget.Toast; + +import java.util.ArrayList; +import java.util.List; + +import fr.gouv.etalab.mastodon.R; +import fr.gouv.etalab.mastodon.asynctasks.RetrieveRelationshipAsyncTask; +import fr.gouv.etalab.mastodon.asynctasks.RetrieveRemoteDataAsyncTask; +import fr.gouv.etalab.mastodon.client.Entities.Account; +import fr.gouv.etalab.mastodon.client.Entities.Error; +import fr.gouv.etalab.mastodon.client.Entities.Relationship; +import fr.gouv.etalab.mastodon.client.Entities.Results; +import fr.gouv.etalab.mastodon.drawers.AccountSearchDevAdapter; +import fr.gouv.etalab.mastodon.helper.ExpandableHeightListView; +import fr.gouv.etalab.mastodon.helper.Helper; +import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRelationshipInterface; +import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRemoteAccountInterface; + + +/** + * Created by Thomas on 31/08/2018. + * About activity + */ + +public class PartnerShipActivity extends BaseActivity implements OnRetrieveRemoteAccountInterface, OnRetrieveRelationshipInterface { + + private List mastohostAcct = new ArrayList<>(); + + private AccountSearchDevAdapter mastohostAdapter; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE); + int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); + switch (theme){ + case Helper.THEME_LIGHT: + setTheme(R.style.AppTheme); + break; + case Helper.THEME_DARK: + setTheme(R.style.AppThemeDark); + break; + case Helper.THEME_BLACK: + setTheme(R.style.AppThemeBlack); + break; + default: + setTheme(R.style.AppThemeDark); + } + + if( getSupportActionBar() != null) + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + setContentView(R.layout.activity_partnership); + + + + TextView about_partnership = findViewById(R.id.about_partnership); + about_partnership.setMovementMethod(LinkMovementMethod.getInstance()); + + ExpandableHeightListView lv_mastohost = findViewById(R.id.lv_mastohost); + + ImageView mastohost = findViewById(R.id.mastohost_logo); + + mastohost.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://masto.host")); + startActivity(browserIntent); + } + }); + + TextView about_mastohost = findViewById(R.id.about_mastohost); + about_mastohost.setMovementMethod(LinkMovementMethod.getInstance()); + + setTitle(R.string.action_partnership); + lv_mastohost.setExpanded(true); + + + mastohostAdapter = new AccountSearchDevAdapter(PartnerShipActivity.this, mastohostAcct); + lv_mastohost.setAdapter(mastohostAdapter); + + + new RetrieveRemoteDataAsyncTask(getApplicationContext(), "mastohost", "mastodon.social", PartnerShipActivity.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 onRetrieveRemoteAccount(Results results) { + SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE); + if( results == null){ + boolean show_error_messages = sharedpreferences.getBoolean(Helper.SET_SHOW_ERROR_MESSAGES, true); + if( show_error_messages) + Toast.makeText(getApplicationContext(), R.string.toast_error,Toast.LENGTH_LONG).show(); + return; + } + List accounts = results.getAccounts(); + Account account; + if( accounts != null && accounts.size() > 0){ + account = accounts.get(0); + account.setFollowing(true); + switch (account.getUsername()) { + case "mastohost": + mastohostAcct.add(account); + mastohostAdapter.notifyDataSetChanged(); + break; + } + new RetrieveRelationshipAsyncTask(getApplicationContext(), account.getId(),PartnerShipActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + } + + + @Override + public void onResume(){ + super.onResume(); + if( mastohostAcct != null){ + for(Account account: mastohostAcct){ + new RetrieveRelationshipAsyncTask(getApplicationContext(), account.getId(),PartnerShipActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + } + } + + @Override + public void onRetrieveRelationship(Relationship relationship, Error error) { + SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE); + String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, ""); + if( error != null){ + return; + } + for( int i = 0 ; i < mastohostAcct.size() ; i++){ + if( mastohostAcct.get(i).getId() != null && mastohostAcct.get(i).getId().equals(relationship.getId())){ + mastohostAcct.get(i).setFollowing(relationship.isFollowing() || userId.trim().equals(relationship.getId())); + mastohostAdapter.notifyDataSetChanged(); + break; + } + } + } +} diff --git a/app/src/main/res/drawable-hdpi/ic_add_circle.png b/app/src/main/res/drawable-hdpi/ic_add_circle.png new file mode 100644 index 000000000..25b902344 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_add_circle.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_info.png b/app/src/main/res/drawable-hdpi/ic_info.png new file mode 100644 index 000000000..9d95cdc96 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_info.png differ diff --git a/app/src/main/res/drawable-ldpi/ic_add_circle.png b/app/src/main/res/drawable-ldpi/ic_add_circle.png new file mode 100644 index 000000000..0529c9517 Binary files /dev/null and b/app/src/main/res/drawable-ldpi/ic_add_circle.png differ diff --git a/app/src/main/res/drawable-ldpi/ic_info.png b/app/src/main/res/drawable-ldpi/ic_info.png new file mode 100644 index 000000000..5dae6b018 Binary files /dev/null and b/app/src/main/res/drawable-ldpi/ic_info.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_add_circle.png b/app/src/main/res/drawable-mdpi/ic_add_circle.png new file mode 100644 index 000000000..d805665eb Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_add_circle.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_info.png b/app/src/main/res/drawable-mdpi/ic_info.png new file mode 100644 index 000000000..3523ac8df Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_info.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_add_circle.png b/app/src/main/res/drawable-xhdpi/ic_add_circle.png new file mode 100644 index 000000000..879fde015 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_add_circle.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_info.png b/app/src/main/res/drawable-xhdpi/ic_info.png new file mode 100644 index 000000000..d65e6aaac Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_info.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_add_circle.png b/app/src/main/res/drawable-xxhdpi/ic_add_circle.png new file mode 100644 index 000000000..f28e33d50 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_add_circle.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_info.png b/app/src/main/res/drawable-xxhdpi/ic_info.png new file mode 100644 index 000000000..3308b273f Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_info.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_add_circle.png b/app/src/main/res/drawable-xxxhdpi/ic_add_circle.png new file mode 100644 index 000000000..9ccea1738 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_add_circle.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_info.png b/app/src/main/res/drawable-xxxhdpi/ic_info.png new file mode 100644 index 000000000..3c2978340 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_info.png differ diff --git a/app/src/main/res/drawable/mastohost.png b/app/src/main/res/drawable/mastohost.png new file mode 100644 index 000000000..422e491c1 Binary files /dev/null and b/app/src/main/res/drawable/mastohost.png differ diff --git a/app/src/main/res/layout/activity_partnership.xml b/app/src/main/res/layout/activity_partnership.xml new file mode 100644 index 000000000..b20ba099a --- /dev/null +++ b/app/src/main/res/layout/activity_partnership.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/menu/activity_main_drawer.xml b/app/src/main/res/menu/activity_main_drawer.xml index d2f8f6112..3621b3746 100644 --- a/app/src/main/res/menu/activity_main_drawer.xml +++ b/app/src/main/res/menu/activity_main_drawer.xml @@ -31,14 +31,6 @@ android:id="@+id/nav_bookmarks" android:icon="@drawable/ic_bookmark" android:title="@string/bookmarks" /> - - + + + + + + + + diff --git a/app/src/main/res/menu/main.xml b/app/src/main/res/menu/main.xml index 3c89317d6..9d007a3d9 100644 --- a/app/src/main/res/menu/main.xml +++ b/app/src/main/res/menu/main.xml @@ -1,10 +1,6 @@ - Mastalab has stopped :( You can send me by email the crash report. It will help to fix it :)\n\nYou can add additional content. Thank you! Ask for sending crash reports by email? + masto.host + + Mastalab has a partnership with Masto.host\nMasto.host offers hosting for Mastalab\'s instance for free.\nThis helps me to better understand how to manage an instance. If one day the API is open to moderators, + I would be glad to be able to test new features. + + Masto.host is a fully managed Mastodon hosting service, meaning that you can create your own instance without having to touch a single line of code or maintain your own server. + Partnerships + Information HTTP SOCKS