fedilab-Android-App/app/src/main/java/app/fedilab/android/activities/OpencollectiveActivity.java

163 lines
6.4 KiB
Java
Raw Normal View History

2019-02-07 19:47:53 +01:00
/* Copyright 2017 Thomas Schneider
*
2019-05-18 11:10:30 +02:00
* This file is a part of Fedilab
2019-02-07 19:47:53 +01:00
*
* 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.
*
2019-05-18 11:10:30 +02:00
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
2019-02-07 19:47:53 +01:00
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
2019-05-18 11:10:30 +02:00
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
2019-02-07 19:47:53 +01:00
* see <http://www.gnu.org/licenses>. */
2019-05-18 11:10:30 +02:00
package app.fedilab.android.activities;
2019-02-07 19:47:53 +01:00
import android.content.Intent;
import android.content.SharedPreferences;
2019-11-13 12:54:01 +01:00
import android.graphics.drawable.ColorDrawable;
2019-02-07 19:47:53 +01:00
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
2019-08-18 17:41:10 +02:00
import android.widget.LinearLayout;
2019-02-07 19:47:53 +01:00
import android.widget.TextView;
import android.widget.Toast;
2019-11-15 16:32:25 +01:00
import androidx.appcompat.app.ActionBar;
import androidx.core.content.ContextCompat;
2019-02-07 19:47:53 +01:00
import java.util.ArrayList;
import java.util.List;
2019-11-15 16:32:25 +01:00
import app.fedilab.android.R;
import app.fedilab.android.asynctasks.RetrieveOpenCollectiveAsyncTask;
2019-05-18 11:10:30 +02:00
import app.fedilab.android.client.Entities.Account;
import app.fedilab.android.client.Entities.Results;
import app.fedilab.android.drawers.AccountSearchDevAdapter;
import app.fedilab.android.helper.ExpandableHeightListView;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.interfaces.OnRetrieveRemoteAccountInterface;
2019-11-15 16:32:25 +01:00
import es.dmoral.toasty.Toasty;
2019-02-07 19:47:53 +01:00
/**
* Created by Thomas on 08/02/2019.
* Opencollective activity
*/
public class OpencollectiveActivity extends BaseActivity implements OnRetrieveRemoteAccountInterface {
private List<Account> bakers = new ArrayList<>();
private List<Account> sponsors = new ArrayList<>();
private AccountSearchDevAdapter backersAdapter;
private AccountSearchDevAdapter sponsorsAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
2019-05-18 11:10:30 +02:00
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
2019-02-07 19:47:53 +01:00
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
2019-09-06 17:55:14 +02:00
switch (theme) {
2019-02-07 19:47:53 +01:00
case Helper.THEME_LIGHT:
2019-11-09 15:47:38 +01:00
setTheme(R.style.AppTheme_Fedilab);
2019-02-07 19:47:53 +01:00
break;
case Helper.THEME_BLACK:
setTheme(R.style.AppThemeBlack);
break;
default:
setTheme(R.style.AppThemeDark);
}
2019-09-06 17:55:14 +02:00
if (getSupportActionBar() != null)
2019-02-07 19:47:53 +01:00
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ActionBar actionBar = getSupportActionBar();
2019-09-06 17:55:14 +02:00
if (actionBar != null) {
2019-11-13 12:54:01 +01:00
actionBar.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(OpencollectiveActivity.this, R.color.cyanea_primary)));
2019-05-18 11:10:30 +02:00
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
2019-02-07 19:47:53 +01:00
assert inflater != null;
2019-08-18 17:41:10 +02:00
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false);
2019-02-07 19:47:53 +01:00
actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close);
TextView toolbar_title = actionBar.getCustomView().findViewById(R.id.toolbar_title);
toolbar_close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
2019-02-09 08:42:30 +01:00
toolbar_title.setText("Open Collective");
2019-02-07 19:47:53 +01:00
}
setContentView(R.layout.activity_opencollective);
ExpandableHeightListView lv_backers = findViewById(R.id.lv_backers);
ExpandableHeightListView lv_sponsors = findViewById(R.id.lv_sponsors);
Button about_opencollective = findViewById(R.id.about_opencollective);
about_opencollective.setOnClickListener(new View.OnClickListener() {
2019-09-06 17:55:14 +02:00
@Override
public void onClick(View v) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://opencollective.com/mastalab"));
startActivity(browserIntent);
}
2019-02-07 19:47:53 +01:00
});
setTitle("Open Collective");
lv_backers.setExpanded(true);
lv_sponsors.setExpanded(true);
2019-08-19 09:11:23 +02:00
backersAdapter = new AccountSearchDevAdapter(bakers);
2019-02-07 19:47:53 +01:00
lv_backers.setAdapter(backersAdapter);
2019-08-19 09:11:23 +02:00
sponsorsAdapter = new AccountSearchDevAdapter(sponsors);
2019-02-07 19:47:53 +01:00
lv_sponsors.setAdapter(sponsorsAdapter);
new RetrieveOpenCollectiveAsyncTask(getApplicationContext(), RetrieveOpenCollectiveAsyncTask.Type.BACKERS, OpencollectiveActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
2019-09-06 17:55:14 +02:00
new RetrieveOpenCollectiveAsyncTask(getApplicationContext(), RetrieveOpenCollectiveAsyncTask.Type.SPONSORS, OpencollectiveActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
2019-02-07 19:47:53 +01:00
@Override
public boolean onOptionsItemSelected(MenuItem item) {
2019-11-09 17:36:17 +01:00
if (item.getItemId() == android.R.id.home) {
finish();
return true;
2019-02-07 19:47:53 +01:00
}
2019-11-09 17:36:17 +01:00
return super.onOptionsItemSelected(item);
2019-02-07 19:47:53 +01:00
}
@Override
public void onRetrieveRemoteAccount(Results results) {
2019-05-18 11:10:30 +02:00
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
2019-09-06 17:55:14 +02:00
if (results == null) {
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
2019-02-07 19:47:53 +01:00
return;
}
List<Account> accounts = results.getAccounts();
2019-09-06 17:55:14 +02:00
if (accounts != null && accounts.size() > 0) {
if (accounts.get(0).getSocial().equals("OPENCOLLECTIVE_BACKER")) {
2019-02-07 19:47:53 +01:00
bakers.addAll(accounts);
backersAdapter.notifyDataSetChanged();
2019-09-06 17:55:14 +02:00
} else if (accounts.get(0).getSocial().equals("OPENCOLLECTIVE_SPONSOR")) {
2019-02-07 19:47:53 +01:00
sponsors.addAll(accounts);
sponsorsAdapter.notifyDataSetChanged();
}
}
}
}