Add partnership and prepare beta 21

This commit is contained in:
Thomas 2022-06-12 11:28:13 +02:00
parent 7915bd4fb0
commit 5db8bfd0b3
17 changed files with 349 additions and 37 deletions

View File

@ -9,9 +9,8 @@ android {
defaultConfig {
minSdk 21
targetSdk 31
versionCode 21
versionName "beta-21"
versionCode 385
versionName "3.0.0-beta-22"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
flavorDimensions "default"
@ -27,13 +26,13 @@ android {
}
productFlavors {
fdroid {
applicationId "fr.gouv.etalab.mastodon.test"
applicationId "fr.gouv.etalab.mastodon"
buildConfigField "boolean", "DONATIONS", "true"
buildConfigField "boolean", "push", "false"
flavor = "fdroid"
}
playstore {
applicationId "app.fedilab.android.test"
applicationId "app.fedilab.android"
buildConfigField "boolean", "DONATIONS", "false"
buildConfigField "boolean", "push", "true"
flavor = "playstore"
@ -98,8 +97,8 @@ dependencies {
implementation project(path: ':cropper')
annotationProcessor "com.github.bumptech.glide:compiler:4.12.0"
implementation 'jp.wasabeef:glide-transformations:4.3.0'
implementation 'com.github.penfeizhou.android.animation:apng:2.17.0'
implementation 'com.github.penfeizhou.android.animation:gif:2.17.0'
implementation 'com.github.penfeizhou.android.animation:apng:2.22.0'
implementation 'com.github.penfeizhou.android.animation:gif:2.22.0'
implementation 'com.google.android.exoplayer:exoplayer:2.16.1'
implementation 'com.github.piasy:rxandroidaudio:1.7.0'
implementation 'com.github.piasy:AudioProcessor:1.7.0'

View File

@ -108,6 +108,12 @@
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/action_about"
android:theme="@style/AppThemeBar" />
<activity
android:name=".activities.PartnerShipActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/action_about"
android:theme="@style/AppThemeBar" />
<activity
android:name=".activities.ActionActivity"
android:configChanges="keyboardHidden|orientation|screenSize"

View File

@ -91,6 +91,7 @@ import app.fedilab.android.activities.InstanceHealthActivity;
import app.fedilab.android.activities.LoginActivity;
import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.activities.MastodonListActivity;
import app.fedilab.android.activities.PartnerShipActivity;
import app.fedilab.android.activities.ProfileActivity;
import app.fedilab.android.activities.ProxyActivity;
import app.fedilab.android.activities.ReorderTimelinesActivity;
@ -347,6 +348,9 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
} else if (id == R.id.nav_about) {
Intent intent = new Intent(this, AboutActivity.class);
startActivity(intent);
} else if (id == R.id.nav_partnership) {
Intent intent = new Intent(this, PartnerShipActivity.class);
startActivity(intent);
}
binding.drawerLayout.close();
return false;

View File

@ -78,12 +78,13 @@ public class AboutActivity extends BaseActivity {
}
binding.aboutSupportPaypal.setOnClickListener(v -> Helper.openBrowser(AboutActivity.this, "https://www.paypal.me/Mastalab"));
binding.accountFollow.setBackgroundTintList(ThemeHelper.getButtonActionColorStateList(AboutActivity.this));
if (BuildConfig.DONATIONS) {
binding.aboutSupportPaypal.setVisibility(View.VISIBLE);
} else {
binding.aboutSupportPaypal.setVisibility(View.GONE);
}
binding.accountFollow.setImageResource(R.drawable.ic_baseline_person_add_24);
binding.aboutWebsite.setOnClickListener(v -> Helper.openBrowser(AboutActivity.this, "https://fedilab.app"));
CrossActionHelper.fetchRemoteAccount(AboutActivity.this, "@apps@toot.fedilab.app", new CrossActionHelper.Callback() {
@Override

View File

@ -0,0 +1,139 @@
package app.fedilab.android.activities;
/* Copyright 2022 Thomas Schneider
*
* This file is a part of Fedilab
*
* 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.
*
* Fedilab 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.
*
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.appcompat.app.ActionBar;
import androidx.core.app.ActivityOptionsCompat;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.ViewModelProvider;
import java.util.ArrayList;
import java.util.List;
import app.fedilab.android.R;
import app.fedilab.android.client.entities.api.Account;
import app.fedilab.android.client.entities.api.Status;
import app.fedilab.android.databinding.ActivityPartnershipBinding;
import app.fedilab.android.helper.CrossActionHelper;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.MastodonHelper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.viewmodel.mastodon.AccountsVM;
public class PartnerShipActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeHelper.applyThemeBar(this);
ActivityPartnershipBinding binding = ActivityPartnershipBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
}
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
assert inflater != null;
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(PartnerShipActivity.this), false);
view.setBackground(new ColorDrawable(ContextCompat.getColor(PartnerShipActivity.this, R.color.cyanea_primary)));
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(v -> finish());
toolbar_title.setText(R.string.action_partnership);
}
TextView about_partnership = findViewById(R.id.about_partnership);
about_partnership.setMovementMethod(LinkMovementMethod.getInstance());
binding.mastohostLogo.setOnClickListener(v -> {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://masto.host"));
startActivity(browserIntent);
});
binding.accountFollow.setBackgroundTintList(ThemeHelper.getButtonActionColorStateList(PartnerShipActivity.this));
setTitle(R.string.action_partnership);
binding.accountFollow.setImageResource(R.drawable.ic_baseline_person_add_24);
CrossActionHelper.fetchRemoteAccount(PartnerShipActivity.this, "@mastohost@mastodon.social", new CrossActionHelper.Callback() {
@Override
public void federatedStatus(Status status) {
}
@Override
public void federatedAccount(Account account) {
if (account != null && account.username.equalsIgnoreCase("mastohost")) {
binding.acccountContainer.setVisibility(View.VISIBLE);
MastodonHelper.loadPPMastodon(binding.accountPp, account);
binding.accountDn.setText(account.display_name);
binding.accountUn.setText(account.acct);
binding.accountPp.setOnClickListener(v -> {
Intent intent = new Intent(PartnerShipActivity.this, ProfileActivity.class);
Bundle b = new Bundle();
b.putSerializable(Helper.ARG_ACCOUNT, account);
intent.putExtras(b);
ActivityOptionsCompat options = ActivityOptionsCompat
.makeSceneTransitionAnimation(PartnerShipActivity.this, binding.accountPp, getString(R.string.activity_porfile_pp));
startActivity(intent, options.toBundle());
});
AccountsVM accountsVM = new ViewModelProvider(PartnerShipActivity.this).get(AccountsVM.class);
List<String> ids = new ArrayList<>();
ids.add(account.id);
accountsVM.getRelationships(MainActivity.currentInstance, MainActivity.currentToken, ids)
.observe(PartnerShipActivity.this, relationShips -> {
if (relationShips != null && relationShips.size() > 0) {
if (!relationShips.get(0).following) {
binding.accountFollow.setVisibility(View.VISIBLE);
binding.accountFollow.setOnClickListener(v -> accountsVM.follow(MainActivity.currentInstance, MainActivity.currentToken, account.id, true, false)
.observe(PartnerShipActivity.this, relationShip -> binding.accountFollow.setVisibility(View.GONE)));
}
}
});
}
}
});
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
}

View File

@ -536,7 +536,7 @@ public class ProfileActivity extends BaseActivity {
private void updateAccount() {
//The value for account is from same server so id can be used
if (account.id.equals(BaseMainActivity.accountWeakReference.get().user_id)) {
if (BaseMainActivity.accountWeakReference.get() != null && account.id.equals(BaseMainActivity.accountWeakReference.get().user_id)) {
binding.accountFollow.setVisibility(View.GONE);
binding.headerEditProfile.setVisibility(View.VISIBLE);
binding.headerEditProfile.bringToFront();
@ -563,20 +563,7 @@ public class ProfileActivity extends BaseActivity {
});
}
}
int[][] states = new int[][]{
new int[]{android.R.attr.state_enabled}, // enabled
new int[]{-android.R.attr.state_enabled}, // disabled
new int[]{-android.R.attr.state_checked}, // unchecked
new int[]{android.R.attr.state_pressed} // pressed
};
int[] colors = new int[]{
ContextCompat.getColor(ProfileActivity.this, R.color.mastodonC4),
ContextCompat.getColor(ProfileActivity.this, R.color.mastodonC4___),
ContextCompat.getColor(ProfileActivity.this, R.color.mastodonC4),
ContextCompat.getColor(ProfileActivity.this, R.color.mastodonC4)
};
binding.accountFollow.setBackgroundTintList(new ColorStateList(states, colors));
binding.accountFollow.setBackgroundTintList(ThemeHelper.getButtonActionColorStateList(ProfileActivity.this));
binding.accountFollow.setEnabled(true);
//Visibility depending of the relationship
if (relationship != null) {

View File

@ -151,6 +151,7 @@ public class Helper {
public static final String INSTANCE_SOCIAL_KEY = "jGj9gW3z9ptyIpB8CMGhAlTlslcemMV6AgoiImfw3vPP98birAJTHOWiu5ZWfCkLvcaLsFZw9e3Pb7TIwkbIyrj3z6S7r2oE6uy6EFHvls3YtapP8QKNZ980p9RfzTb4";
public static final String WEBSITE_VALUE = "https://fedilab.app";
public static final String OLD_DB_NAME = "mastodon_etalab_db";
public static final String RECEIVE_TOAST_MESSAGE = "RECEIVE_TOAST_MESSAGE";
public static final String RECEIVE_TOAST_TYPE = "RECEIVE_TOAST_TYPE";
@ -1572,4 +1573,28 @@ public class Helper {
}).start();
}
}
public static void transfertIfExist(Context context) {
File dbFile = context.getDatabasePath(OLD_DB_NAME);
if (!dbFile.exists()) {
return;
}
int version = -1;
try {
SQLiteDatabase sqlDb = SQLiteDatabase.openDatabase
(context.getDatabasePath(OLD_DB_NAME).getAbsolutePath(), null, SQLiteDatabase.OPEN_READONLY);
version = sqlDb.getVersion();
} catch (Exception ignored) {
}
try {
if (version == -1) {
version = 38;
}
SQLiteDatabase oldDb = Sqlite.getInstance(context.getApplicationContext(), OLD_DB_NAME, null, version).open();
} catch (Exception ignored) {
}
context.deleteDatabase(OLD_DB_NAME);
}
}

View File

@ -263,10 +263,13 @@ public class PinnedTimelineHelper {
try {
//If some menu items have been hidden we should not create tab for them
bottomMenuDb = new BottomMenu(context).getAllBottomMenu(MainActivity.accountWeakReference.get());
if (bottomMenuDb != null && bottomMenuDb.bottom_menu != null) {
for (BottomMenu.MenuItem menuItem : bottomMenuDb.bottom_menu) {
if (!menuItem.visible) {
toRemove++;
if (bottomMenuDb != null) {
List<BottomMenu.MenuItem> menuItemList = bottomMenuDb.bottom_menu;
if (menuItemList != null) {
for (BottomMenu.MenuItem menuItem : menuItemList) {
if (!menuItem.visible) {
toRemove++;
}
}
}
}

View File

@ -710,8 +710,8 @@ public class SpannableHelper {
} catch (Exception ignored) {
}
} else {
Drawable drawable = Drawable.createFromPath(file.getAbsolutePath());
try {
Drawable drawable = Drawable.createFromPath(file.getAbsolutePath());
drawable.setBounds(0, 0, (int) convertDpToPixel(20, context), (int) convertDpToPixel(20, context));
drawable.setVisible(true, true);
imageSpan = new ImageSpan(drawable);

View File

@ -282,6 +282,24 @@ public class ThemeHelper {
return new ColorStateList(states, colors);
}
public static ColorStateList getButtonActionColorStateList(Context context) {
int[][] states = new int[][]{
new int[]{android.R.attr.state_enabled}, // enabled
new int[]{-android.R.attr.state_enabled}, // disabled
new int[]{-android.R.attr.state_checked}, // unchecked
new int[]{android.R.attr.state_pressed} // pressed
};
int alphaColor = ColorUtils.setAlphaComponent(ContextCompat.getColor(context, R.color.cyanea_accent_dark_reference), 0x33);
int color = ContextCompat.getColor(context, R.color.cyanea_accent_dark_reference);
int[] colors = new int[]{
color,
alphaColor,
color,
color
};
return new ColorStateList(states, colors);
}
/**
* Allow to set colors for having description on media

View File

@ -149,8 +149,11 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
private int getPosition(Status status) {
int position = 0;
boolean found = false;
if (status.id == null) {
return -1;
}
for (Status _status : statuses) {
if (_status.id.compareTo(status.id) == 0) {
if (_status.id != null && _status.id.compareTo(status.id) == 0) {
found = true;
break;
}

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#FFFFFF"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10s10,-4.48 10,-10S17.52,2 12,2zM12,6c1.93,0 3.5,1.57 3.5,3.5S13.93,13 12,13s-3.5,-1.57 -3.5,-3.5S10.07,6 12,6zM12,20c-2.03,0 -4.43,-0.82 -6.14,-2.88C7.55,15.8 9.68,15 12,15s4.45,0.8 6.14,2.12C16.43,19.18 14.03,20 12,20z" />
</vector>

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

View File

@ -61,8 +61,11 @@
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/acccount_container"
android:layout_width="match_parent"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
tools:visibility="visible"
android:visibility="gone">
<androidx.appcompat.widget.AppCompatImageView
@ -74,19 +77,16 @@
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="0dp"
android:padding="10dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/account_dn"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="16sp" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/account_un"
android:layout_width="wrap_content"
@ -95,16 +95,17 @@
android:textSize="14sp" />
</androidx.appcompat.widget.LinearLayoutCompat>
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/account_follow"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="6dp"
android:layout_marginTop="6dp"
android:layout_margin="10dp"
android:contentDescription="@string/make_an_action"
android:scaleType="fitCenter"
android:visibility="gone"
android:tint="@color/white"
app:layout_constraintStart_toEndOf="@id/avatar_container"
app:layout_constraintTop_toBottomOf="@id/banner_container"
tools:src="@drawable/ic_baseline_person_add_24"

View File

@ -0,0 +1,111 @@
<?xml version="1.0" encoding="utf-8"?><!--
Copyright 2022 Thomas Schneider
This file is a part of Fedilab
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.
Fedilab 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.
You should have received a copy of the GNU General Public License along with Fedilab; if not,
see <http://www.gnu.org/licenses>.
-->
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="@dimen/fab_margin"
android:layout_marginLeft="@dimen/fab_margin"
android:layout_marginEnd="@dimen/fab_margin"
android:layout_marginRight="@dimen/fab_margin"
android:orientation="vertical">
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- About masto.host -->
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/mastohost_logo"
android:layout_width="200dp"
android:layout_height="110dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:contentDescription="@string/mastohost_logo"
android:src="@drawable/mastohost" />
<!-- About partnership -->
<TextView
android:id="@+id/about_partnership"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginBottom="20dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:text="@string/about_partnership"
android:textSize="16sp" />
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/acccount_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone"
tools:visibility="visible">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/account_pp"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_margin="10dp"
android:contentDescription="@string/profile_picture" />
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:padding="10dp">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/account_dn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="16sp" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/account_un"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="14sp" />
</androidx.appcompat.widget.LinearLayoutCompat>
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/account_follow"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_margin="10dp"
android:contentDescription="@string/make_an_action"
android:scaleType="fitCenter"
android:tint="@color/white"
android:visibility="gone"
app:layout_constraintStart_toEndOf="@id/avatar_container"
app:layout_constraintTop_toBottomOf="@id/banner_container"
tools:src="@drawable/ic_baseline_person_add_24"
tools:visibility="visible" />
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.appcompat.widget.LinearLayoutCompat>
</ScrollView>

View File

@ -50,5 +50,10 @@
android:id="@+id/nav_about"
android:icon="@drawable/ic_baseline_info_24"
android:title="@string/action_about" />
<item
android:id="@+id/nav_partnership"
android:icon="@drawable/ic_baseline_account_circle_24"
android:title="@string/action_partnership" />
</group>
</menu>

View File

@ -542,7 +542,7 @@
<string name="follow_instance">Follow instance</string>
<string name="toast_instance_already_added">You already follow this instance!</string>
<string name="toast_instance_followed">The instance is followed!</string>
<string name="about_partnership" translatable="false"><b>Masto.host</b> is our Mastodon hosting partner.\n\nWith this partnership they provide me free hosting for <a href="https://ins.mastalab.app">Mastalab\'s instance</a> and in exchange I promote them in here.\n\nTo be clear, there is no money involved or tracking of users. I needed an instance for testing, we talked and agreed on this.\n\n<a href="https://masto.host">Go check them out</a> if you want to run your own Mastodon instance.</string>
<string name="about_partnership" translatable="false"><b>Masto.host</b> is our Mastodon hosting partner.\n\nWith this partnership they provide me free hosting for <a href="https://toot.fedilab.app">Fedilab\'s instance</a> and in exchange I promote them in here.\n\nTo be clear, there is no money involved or tracking of users. I needed an instance for testing, we talked and agreed on this.\n\n<a href="https://masto.host">Go check them out</a> if you want to run your own Mastodon instance.</string>
<string name="action_partnership">Partnerships</string>
<string name="neutral_menu_information">Information</string>