forked from mirrors/Fedilab
improvements
This commit is contained in:
parent
1b429a31a2
commit
c09a7a3c2b
12 changed files with 256 additions and 292 deletions
|
@ -18,6 +18,7 @@ import static app.fedilab.android.BaseMainActivity.status.DISCONNECTED;
|
||||||
import static app.fedilab.android.BaseMainActivity.status.UNKNOWN;
|
import static app.fedilab.android.BaseMainActivity.status.UNKNOWN;
|
||||||
import static app.fedilab.android.mastodon.helper.CacheHelper.deleteDir;
|
import static app.fedilab.android.mastodon.helper.CacheHelper.deleteDir;
|
||||||
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_TOKEN;
|
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_TOKEN;
|
||||||
|
import static app.fedilab.android.mastodon.helper.Helper.TAG;
|
||||||
import static app.fedilab.android.mastodon.helper.Helper.displayReleaseNotesIfNeeded;
|
import static app.fedilab.android.mastodon.helper.Helper.displayReleaseNotesIfNeeded;
|
||||||
import static app.fedilab.android.mastodon.ui.drawer.StatusAdapter.sendAction;
|
import static app.fedilab.android.mastodon.ui.drawer.StatusAdapter.sendAction;
|
||||||
|
|
||||||
|
@ -41,6 +42,7 @@ import android.provider.BaseColumns;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
|
import android.util.Log;
|
||||||
import android.util.Patterns;
|
import android.util.Patterns;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
|
@ -335,8 +337,195 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
||||||
});
|
});
|
||||||
permissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS);
|
permissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS);
|
||||||
}
|
}
|
||||||
|
NavHeaderMainBinding headerMainBinding = NavHeaderMainBinding.inflate(getLayoutInflater());
|
||||||
|
currentAccount = null;
|
||||||
|
//Update account details
|
||||||
|
new Thread(() -> {
|
||||||
|
try {
|
||||||
|
if (currentToken == null) {
|
||||||
|
currentToken = sharedpreferences.getString(Helper.PREF_USER_TOKEN, null);
|
||||||
|
}
|
||||||
|
currentAccount = new Account(BaseMainActivity.this).getConnectedAccount();
|
||||||
|
Log.v(TAG, "currentToken! " + currentToken);
|
||||||
|
Log.v(TAG, "currentAccount! " + currentAccount);
|
||||||
|
if (currentAccount != null && currentAccount.api == Account.API.PEERTUBE) {
|
||||||
|
startActivity(new Intent(this, PeertubeBaseMainActivity.class));
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
} catch (DBException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
//If the attached account is null, the app will fetch remote instance to get up-to-date values
|
||||||
|
if (currentAccount != null && currentAccount.mastodon_account == null) {
|
||||||
|
OkHttpClient okHttpClient = new OkHttpClient.Builder()
|
||||||
|
.readTimeout(60, TimeUnit.SECONDS)
|
||||||
|
.connectTimeout(60, TimeUnit.SECONDS)
|
||||||
|
.callTimeout(60, TimeUnit.SECONDS)
|
||||||
|
.proxy(Helper.getProxy(getApplication().getApplicationContext()))
|
||||||
|
.build();
|
||||||
|
Retrofit retrofit = new Retrofit.Builder()
|
||||||
|
.baseUrl("https://" + MainActivity.currentInstance + "/api/v1/")
|
||||||
|
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
|
||||||
|
.client(okHttpClient)
|
||||||
|
.build();
|
||||||
|
MastodonAccountsService mastodonAccountsService = retrofit.create(MastodonAccountsService.class);
|
||||||
|
retrofit2.Call<app.fedilab.android.mastodon.client.entities.api.Account> accountCall = mastodonAccountsService.verify_credentials(MainActivity.currentToken);
|
||||||
|
if (accountCall != null) {
|
||||||
|
try {
|
||||||
|
retrofit2.Response<app.fedilab.android.mastodon.client.entities.api.Account> accountResponse = accountCall.execute();
|
||||||
|
if (accountResponse.isSuccessful()) {
|
||||||
|
currentAccount.mastodon_account = accountResponse.body();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||||
|
Runnable myRunnable = () -> {
|
||||||
|
if (currentAccount == null || currentAccount.mastodon_account == null) {
|
||||||
|
//It is not, the user is redirected to the login page
|
||||||
|
Intent myIntent = new Intent(BaseMainActivity.this, LoginActivity.class);
|
||||||
|
startActivity(myIntent);
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bottomMenu = new BottomMenu(BaseMainActivity.this).hydrate(currentAccount, binding.bottomNavView);
|
||||||
|
if (currentAccount.mastodon_account.locked) {
|
||||||
|
binding.navView.getMenu().findItem(R.id.nav_follow_requests).setVisible(true);
|
||||||
|
}
|
||||||
|
if (currentAccount.admin) {
|
||||||
|
binding.navView.getMenu().findItem(R.id.nav_administration).setVisible(true);
|
||||||
|
}
|
||||||
|
if (bottomMenu != null) {
|
||||||
|
//ManageClick on bottom menu items
|
||||||
|
if (binding.bottomNavView.findViewById(R.id.nav_home) != null) {
|
||||||
|
binding.bottomNavView.findViewById(R.id.nav_home).setOnLongClickListener(view -> {
|
||||||
|
int position = BottomMenu.getPosition(bottomMenu, R.id.nav_home);
|
||||||
|
if (position >= 0) {
|
||||||
|
manageFilters(position);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (binding.bottomNavView.findViewById(R.id.nav_local) != null) {
|
||||||
|
binding.bottomNavView.findViewById(R.id.nav_local).setOnLongClickListener(view -> {
|
||||||
|
int position = BottomMenu.getPosition(bottomMenu, R.id.nav_local);
|
||||||
|
if (position >= 0) {
|
||||||
|
manageFilters(position);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (binding.bottomNavView.findViewById(R.id.nav_public) != null) {
|
||||||
|
binding.bottomNavView.findViewById(R.id.nav_public).setOnLongClickListener(view -> {
|
||||||
|
int position = BottomMenu.getPosition(bottomMenu, R.id.nav_public);
|
||||||
|
if (position >= 0) {
|
||||||
|
manageFilters(position);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
binding.bottomNavView.setOnItemSelectedListener(item -> {
|
||||||
|
int itemId = item.getItemId();
|
||||||
|
int position = BottomMenu.getPosition(bottomMenu, itemId);
|
||||||
|
if (position >= 0) {
|
||||||
|
if (binding.viewPager.getCurrentItem() == position) {
|
||||||
|
scrollToTop();
|
||||||
|
binding.bottomNavView.removeBadge(itemId);
|
||||||
|
} else {
|
||||||
|
binding.viewPager.setCurrentItem(position, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
currentInstance = currentAccount.instance;
|
||||||
|
currentUserID = currentAccount.user_id;
|
||||||
|
|
||||||
|
show_boosts = sharedpreferences.getBoolean(getString(R.string.SET_SHOW_BOOSTS) + currentUserID + currentInstance, true);
|
||||||
|
show_replies = sharedpreferences.getBoolean(getString(R.string.SET_SHOW_REPLIES) + currentUserID + currentInstance, true);
|
||||||
|
show_dms = sharedpreferences.getBoolean(getString(R.string.SET_SHOW_DMS) + currentUserID + currentInstance, true);
|
||||||
|
regex_home = sharedpreferences.getString(getString(R.string.SET_FILTER_REGEX_HOME) + currentUserID + currentInstance, null);
|
||||||
|
regex_local = sharedpreferences.getString(getString(R.string.SET_FILTER_REGEX_LOCAL) + currentUserID + currentInstance, null);
|
||||||
|
regex_public = sharedpreferences.getString(getString(R.string.SET_FILTER_REGEX_PUBLIC) + currentUserID + currentInstance, null);
|
||||||
|
show_art_nsfw = sharedpreferences.getBoolean(getString(R.string.SET_ART_WITH_NSFW) + currentUserID + currentInstance, false);
|
||||||
|
|
||||||
|
binding.profilePicture.setOnClickListener(v -> binding.drawerLayout.openDrawer(GravityCompat.START));
|
||||||
|
Helper.loadPP(BaseMainActivity.this, binding.profilePicture, currentAccount);
|
||||||
|
headerMainBinding.accountAcc.setText(String.format("%s@%s", currentAccount.mastodon_account.username, currentAccount.instance));
|
||||||
|
if (currentAccount.mastodon_account.display_name == null || currentAccount.mastodon_account.display_name.isEmpty()) {
|
||||||
|
currentAccount.mastodon_account.display_name = currentAccount.mastodon_account.acct;
|
||||||
|
}
|
||||||
|
if (!isFinishing()) {
|
||||||
|
headerMainBinding.accountName.setText(
|
||||||
|
currentAccount.mastodon_account.getSpanDisplayName(BaseMainActivity.this,
|
||||||
|
new WeakReference<>(headerMainBinding.accountName)),
|
||||||
|
TextView.BufferType.SPANNABLE);
|
||||||
|
}
|
||||||
|
float scale = sharedpreferences.getFloat(getString(R.string.SET_FONT_SCALE), 1.1f);
|
||||||
|
headerMainBinding.accountName.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18 * 1.1f / scale);
|
||||||
|
headerMainBinding.accountAcc.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18 * 1.1f / scale);
|
||||||
|
Helper.loadPP(BaseMainActivity.this, headerMainBinding.accountProfilePicture, currentAccount, false);
|
||||||
|
MastodonHelper.loadProfileMediaMastodon(BaseMainActivity.this, headerMainBinding.backgroundImage, currentAccount.mastodon_account, MastodonHelper.MediaAccountType.HEADER);
|
||||||
|
headerMainBinding.backgroundImage.setAlpha(0.5f);
|
||||||
|
/*
|
||||||
|
* Some general data are loaded when the app starts such;
|
||||||
|
* - Pinned timelines (in app feature)
|
||||||
|
* - Instance info (for limits)
|
||||||
|
* - Emoji for picker
|
||||||
|
* - Filters for timelines
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Update pinned timelines
|
||||||
|
new ViewModelProvider(BaseMainActivity.this).get(TopBarVM.class).getDBPinned()
|
||||||
|
.observe(this, pinned -> {
|
||||||
|
this.pinned = pinned;
|
||||||
|
//Initialize the slug of the first fragment
|
||||||
|
//First it's taken from db (last stored values)
|
||||||
|
PinnedTimelineHelper.redrawTopBarPinned(BaseMainActivity.this, binding, pinned, bottomMenu, null);
|
||||||
|
//Fetch remote lists for the authenticated account and update them
|
||||||
|
new ViewModelProvider(BaseMainActivity.this).get(TimelinesVM.class).getLists(currentInstance, currentToken)
|
||||||
|
.observe(this, mastodonLists ->
|
||||||
|
PinnedTimelineHelper.redrawTopBarPinned(BaseMainActivity.this, binding, pinned, bottomMenu, mastodonLists)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
//Update emoji in db for the current instance
|
||||||
|
new ViewModelProvider(BaseMainActivity.this).get(InstancesVM.class).getEmoji(currentInstance);
|
||||||
|
//Retrieve instance info
|
||||||
|
new ViewModelProvider(BaseMainActivity.this).get(InstancesVM.class).getInstance(currentInstance)
|
||||||
|
.observe(BaseMainActivity.this, instance -> {
|
||||||
|
instanceInfo = instance.info;
|
||||||
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
|
editor.putString(getString(R.string.INSTANCE_INFO) + MainActivity.currentInstance, Instance.serialize(instanceInfo));
|
||||||
|
editor.apply();
|
||||||
|
});
|
||||||
|
//Retrieve filters
|
||||||
|
new ViewModelProvider(BaseMainActivity.this).get(FiltersVM.class).getFilters(currentInstance, currentToken)
|
||||||
|
.observe(BaseMainActivity.this, filters -> mainFilters = filters);
|
||||||
|
new ViewModelProvider(BaseMainActivity.this).get(AccountsVM.class).getConnectedAccount(currentInstance, currentToken)
|
||||||
|
.observe(BaseMainActivity.this, mastodonAccount -> {
|
||||||
|
//Initialize static var
|
||||||
|
if (mastodonAccount != null && currentAccount != null) {
|
||||||
|
currentAccount.mastodon_account = mastodonAccount;
|
||||||
|
displayReleaseNotesIfNeeded(BaseMainActivity.this, false);
|
||||||
|
new Thread(() -> {
|
||||||
|
try {
|
||||||
|
//Update account in db
|
||||||
|
new Account(BaseMainActivity.this).insertOrUpdate(currentAccount);
|
||||||
|
} catch (DBException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
mainHandler.post(myRunnable);
|
||||||
|
}).start();
|
||||||
filteredAccounts = new ArrayList<>();
|
filteredAccounts = new ArrayList<>();
|
||||||
mamageNewIntent(getIntent());
|
mamageNewIntent(getIntent());
|
||||||
filterFetched = false;
|
filterFetched = false;
|
||||||
|
@ -363,7 +552,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
||||||
.setOpenableLayout(binding.drawerLayout)
|
.setOpenableLayout(binding.drawerLayout)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
NavHeaderMainBinding headerMainBinding = NavHeaderMainBinding.inflate(getLayoutInflater());
|
|
||||||
binding.navView.addHeaderView(headerMainBinding.getRoot());
|
binding.navView.addHeaderView(headerMainBinding.getRoot());
|
||||||
binding.navView.setNavigationItemSelectedListener(menuItem -> {
|
binding.navView.setNavigationItemSelectedListener(menuItem -> {
|
||||||
int id = menuItem.getItemId();
|
int id = menuItem.getItemId();
|
||||||
|
@ -593,192 +782,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
||||||
});
|
});
|
||||||
popup.show();
|
popup.show();
|
||||||
});
|
});
|
||||||
currentAccount = null;
|
|
||||||
//Update account details
|
|
||||||
new Thread(() -> {
|
|
||||||
try {
|
|
||||||
if (currentToken == null) {
|
|
||||||
currentToken = sharedpreferences.getString(Helper.PREF_USER_TOKEN, null);
|
|
||||||
}
|
|
||||||
currentAccount = new Account(BaseMainActivity.this).getConnectedAccount();
|
|
||||||
if (currentAccount.api == Account.API.PEERTUBE) {
|
|
||||||
startActivity(new Intent(this, PeertubeBaseMainActivity.class));
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
} catch (DBException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
//If the attached account is null, the app will fetch remote instance to get up-to-date values
|
|
||||||
if (currentAccount != null && currentAccount.mastodon_account == null) {
|
|
||||||
OkHttpClient okHttpClient = new OkHttpClient.Builder()
|
|
||||||
.readTimeout(60, TimeUnit.SECONDS)
|
|
||||||
.connectTimeout(60, TimeUnit.SECONDS)
|
|
||||||
.callTimeout(60, TimeUnit.SECONDS)
|
|
||||||
.proxy(Helper.getProxy(getApplication().getApplicationContext()))
|
|
||||||
.build();
|
|
||||||
Retrofit retrofit = new Retrofit.Builder()
|
|
||||||
.baseUrl("https://" + MainActivity.currentInstance + "/api/v1/")
|
|
||||||
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
|
|
||||||
.client(okHttpClient)
|
|
||||||
.build();
|
|
||||||
MastodonAccountsService mastodonAccountsService = retrofit.create(MastodonAccountsService.class);
|
|
||||||
retrofit2.Call<app.fedilab.android.mastodon.client.entities.api.Account> accountCall = mastodonAccountsService.verify_credentials(MainActivity.currentToken);
|
|
||||||
if (accountCall != null) {
|
|
||||||
try {
|
|
||||||
retrofit2.Response<app.fedilab.android.mastodon.client.entities.api.Account> accountResponse = accountCall.execute();
|
|
||||||
if (accountResponse.isSuccessful()) {
|
|
||||||
currentAccount.mastodon_account = accountResponse.body();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
||||||
Runnable myRunnable = () -> {
|
|
||||||
if (currentAccount == null || currentAccount.mastodon_account == null) {
|
|
||||||
//It is not, the user is redirected to the login page
|
|
||||||
Intent myIntent = new Intent(BaseMainActivity.this, LoginActivity.class);
|
|
||||||
startActivity(myIntent);
|
|
||||||
finish();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
bottomMenu = new BottomMenu(BaseMainActivity.this).hydrate(currentAccount, binding.bottomNavView);
|
|
||||||
if (currentAccount.mastodon_account.locked) {
|
|
||||||
binding.navView.getMenu().findItem(R.id.nav_follow_requests).setVisible(true);
|
|
||||||
}
|
|
||||||
if (currentAccount.admin) {
|
|
||||||
binding.navView.getMenu().findItem(R.id.nav_administration).setVisible(true);
|
|
||||||
}
|
|
||||||
if (bottomMenu != null) {
|
|
||||||
//ManageClick on bottom menu items
|
|
||||||
if (binding.bottomNavView.findViewById(R.id.nav_home) != null) {
|
|
||||||
binding.bottomNavView.findViewById(R.id.nav_home).setOnLongClickListener(view -> {
|
|
||||||
int position = BottomMenu.getPosition(bottomMenu, R.id.nav_home);
|
|
||||||
if (position >= 0) {
|
|
||||||
manageFilters(position);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (binding.bottomNavView.findViewById(R.id.nav_local) != null) {
|
|
||||||
binding.bottomNavView.findViewById(R.id.nav_local).setOnLongClickListener(view -> {
|
|
||||||
int position = BottomMenu.getPosition(bottomMenu, R.id.nav_local);
|
|
||||||
if (position >= 0) {
|
|
||||||
manageFilters(position);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (binding.bottomNavView.findViewById(R.id.nav_public) != null) {
|
|
||||||
binding.bottomNavView.findViewById(R.id.nav_public).setOnLongClickListener(view -> {
|
|
||||||
int position = BottomMenu.getPosition(bottomMenu, R.id.nav_public);
|
|
||||||
if (position >= 0) {
|
|
||||||
manageFilters(position);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
binding.bottomNavView.setOnItemSelectedListener(item -> {
|
|
||||||
int itemId = item.getItemId();
|
|
||||||
int position = BottomMenu.getPosition(bottomMenu, itemId);
|
|
||||||
if (position >= 0) {
|
|
||||||
if (binding.viewPager.getCurrentItem() == position) {
|
|
||||||
scrollToTop();
|
|
||||||
binding.bottomNavView.removeBadge(itemId);
|
|
||||||
} else {
|
|
||||||
binding.viewPager.setCurrentItem(position, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
currentInstance = currentAccount.instance;
|
|
||||||
currentUserID = currentAccount.user_id;
|
|
||||||
|
|
||||||
show_boosts = sharedpreferences.getBoolean(getString(R.string.SET_SHOW_BOOSTS) + currentUserID + currentInstance, true);
|
|
||||||
show_replies = sharedpreferences.getBoolean(getString(R.string.SET_SHOW_REPLIES) + currentUserID + currentInstance, true);
|
|
||||||
show_dms = sharedpreferences.getBoolean(getString(R.string.SET_SHOW_DMS) + currentUserID + currentInstance, true);
|
|
||||||
regex_home = sharedpreferences.getString(getString(R.string.SET_FILTER_REGEX_HOME) + currentUserID + currentInstance, null);
|
|
||||||
regex_local = sharedpreferences.getString(getString(R.string.SET_FILTER_REGEX_LOCAL) + currentUserID + currentInstance, null);
|
|
||||||
regex_public = sharedpreferences.getString(getString(R.string.SET_FILTER_REGEX_PUBLIC) + currentUserID + currentInstance, null);
|
|
||||||
show_art_nsfw = sharedpreferences.getBoolean(getString(R.string.SET_ART_WITH_NSFW) + currentUserID + currentInstance, false);
|
|
||||||
|
|
||||||
binding.profilePicture.setOnClickListener(v -> binding.drawerLayout.openDrawer(GravityCompat.START));
|
|
||||||
Helper.loadPP(BaseMainActivity.this, binding.profilePicture, currentAccount);
|
|
||||||
headerMainBinding.accountAcc.setText(String.format("%s@%s", currentAccount.mastodon_account.username, currentAccount.instance));
|
|
||||||
if (currentAccount.mastodon_account.display_name == null || currentAccount.mastodon_account.display_name.isEmpty()) {
|
|
||||||
currentAccount.mastodon_account.display_name = currentAccount.mastodon_account.acct;
|
|
||||||
}
|
|
||||||
if (!isFinishing()) {
|
|
||||||
headerMainBinding.accountName.setText(
|
|
||||||
currentAccount.mastodon_account.getSpanDisplayName(BaseMainActivity.this,
|
|
||||||
new WeakReference<>(headerMainBinding.accountName)),
|
|
||||||
TextView.BufferType.SPANNABLE);
|
|
||||||
}
|
|
||||||
float scale = sharedpreferences.getFloat(getString(R.string.SET_FONT_SCALE), 1.1f);
|
|
||||||
headerMainBinding.accountName.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18 * 1.1f / scale);
|
|
||||||
headerMainBinding.accountAcc.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18 * 1.1f / scale);
|
|
||||||
Helper.loadPP(BaseMainActivity.this, headerMainBinding.accountProfilePicture, currentAccount, false);
|
|
||||||
MastodonHelper.loadProfileMediaMastodon(BaseMainActivity.this, headerMainBinding.backgroundImage, currentAccount.mastodon_account, MastodonHelper.MediaAccountType.HEADER);
|
|
||||||
headerMainBinding.backgroundImage.setAlpha(0.5f);
|
|
||||||
/*
|
|
||||||
* Some general data are loaded when the app starts such;
|
|
||||||
* - Pinned timelines (in app feature)
|
|
||||||
* - Instance info (for limits)
|
|
||||||
* - Emoji for picker
|
|
||||||
* - Filters for timelines
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
//Update pinned timelines
|
|
||||||
new ViewModelProvider(BaseMainActivity.this).get(TopBarVM.class).getDBPinned()
|
|
||||||
.observe(this, pinned -> {
|
|
||||||
this.pinned = pinned;
|
|
||||||
//Initialize the slug of the first fragment
|
|
||||||
//First it's taken from db (last stored values)
|
|
||||||
PinnedTimelineHelper.redrawTopBarPinned(BaseMainActivity.this, binding, pinned, bottomMenu, null);
|
|
||||||
//Fetch remote lists for the authenticated account and update them
|
|
||||||
new ViewModelProvider(BaseMainActivity.this).get(TimelinesVM.class).getLists(currentInstance, currentToken)
|
|
||||||
.observe(this, mastodonLists ->
|
|
||||||
PinnedTimelineHelper.redrawTopBarPinned(BaseMainActivity.this, binding, pinned, bottomMenu, mastodonLists)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
//Update emoji in db for the current instance
|
|
||||||
new ViewModelProvider(BaseMainActivity.this).get(InstancesVM.class).getEmoji(currentInstance);
|
|
||||||
//Retrieve instance info
|
|
||||||
new ViewModelProvider(BaseMainActivity.this).get(InstancesVM.class).getInstance(currentInstance)
|
|
||||||
.observe(BaseMainActivity.this, instance -> {
|
|
||||||
instanceInfo = instance.info;
|
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
||||||
editor.putString(getString(R.string.INSTANCE_INFO) + MainActivity.currentInstance, Instance.serialize(instanceInfo));
|
|
||||||
editor.apply();
|
|
||||||
});
|
|
||||||
//Retrieve filters
|
|
||||||
new ViewModelProvider(BaseMainActivity.this).get(FiltersVM.class).getFilters(currentInstance, currentToken)
|
|
||||||
.observe(BaseMainActivity.this, filters -> mainFilters = filters);
|
|
||||||
new ViewModelProvider(BaseMainActivity.this).get(AccountsVM.class).getConnectedAccount(currentInstance, currentToken)
|
|
||||||
.observe(BaseMainActivity.this, mastodonAccount -> {
|
|
||||||
//Initialize static var
|
|
||||||
if (mastodonAccount != null && currentAccount != null) {
|
|
||||||
currentAccount.mastodon_account = mastodonAccount;
|
|
||||||
displayReleaseNotesIfNeeded(BaseMainActivity.this, false);
|
|
||||||
new Thread(() -> {
|
|
||||||
try {
|
|
||||||
//Update account in db
|
|
||||||
new Account(BaseMainActivity.this).insertOrUpdate(currentAccount);
|
|
||||||
} catch (DBException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
};
|
|
||||||
mainHandler.post(myRunnable);
|
|
||||||
}).start();
|
|
||||||
//Toolbar search
|
//Toolbar search
|
||||||
binding.toolbarSearch.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
binding.toolbarSearch.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -263,8 +263,9 @@ public class Account extends BaseAccount implements Serializable {
|
||||||
if (token.getRefresh_token() != null) {
|
if (token.getRefresh_token() != null) {
|
||||||
values.put(Sqlite.COL_REFRESH_TOKEN, token.getRefresh_token());
|
values.put(Sqlite.COL_REFRESH_TOKEN, token.getRefresh_token());
|
||||||
}
|
}
|
||||||
if (token.getAccess_token() != null)
|
if (token.getAccess_token() != null) {
|
||||||
values.put(Sqlite.COL_TOKEN, token.getAccess_token());
|
values.put(Sqlite.COL_TOKEN, token.getAccess_token());
|
||||||
|
}
|
||||||
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
String userId = sharedpreferences.getString(Helper.PREF_USER_ID, null);
|
String userId = sharedpreferences.getString(Helper.PREF_USER_ID, null);
|
||||||
String instance = HelperInstance.getLiveInstance(context);
|
String instance = HelperInstance.getLiveInstance(context);
|
||||||
|
|
|
@ -182,8 +182,9 @@ public class LoginActivity extends BaseBarActivity {
|
||||||
oauthParams.setPassword(binding.loginPasswd.getText().toString());
|
oauthParams.setPassword(binding.loginPasswd.getText().toString());
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
Log.v(TAG, "token: GET");
|
||||||
Token token = new RetrofitPeertubeAPI(LoginActivity.this, finalInstance, null).manageToken(oauthParams);
|
Token token = new RetrofitPeertubeAPI(LoginActivity.this, finalInstance, null).manageToken(oauthParams);
|
||||||
Log.v(TAG, "token: " + token);
|
Log.v(TAG, ">token: " + token);
|
||||||
proceedLogin(token, finalInstance);
|
proceedLogin(token, finalInstance);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
oauthParams.setUsername(binding.loginUid.getText().toString().toLowerCase().trim());
|
oauthParams.setUsername(binding.loginUid.getText().toString().toLowerCase().trim());
|
||||||
|
|
|
@ -63,6 +63,7 @@ import android.view.WindowManager;
|
||||||
import android.view.animation.Animation;
|
import android.view.animation.Animation;
|
||||||
import android.view.animation.TranslateAnimation;
|
import android.view.animation.TranslateAnimation;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
import android.webkit.WebView;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
@ -155,7 +156,6 @@ import app.fedilab.android.peertube.viewmodel.PlaylistsVM;
|
||||||
import app.fedilab.android.peertube.viewmodel.PostActionsVM;
|
import app.fedilab.android.peertube.viewmodel.PostActionsVM;
|
||||||
import app.fedilab.android.peertube.viewmodel.SearchVM;
|
import app.fedilab.android.peertube.viewmodel.SearchVM;
|
||||||
import app.fedilab.android.peertube.viewmodel.TimelineVM;
|
import app.fedilab.android.peertube.viewmodel.TimelineVM;
|
||||||
import app.fedilab.android.peertube.webview.CustomWebview;
|
|
||||||
import app.fedilab.android.peertube.webview.MastalabWebChromeClient;
|
import app.fedilab.android.peertube.webview.MastalabWebChromeClient;
|
||||||
import app.fedilab.android.peertube.webview.MastalabWebViewClient;
|
import app.fedilab.android.peertube.webview.MastalabWebViewClient;
|
||||||
import es.dmoral.toasty.Toasty;
|
import es.dmoral.toasty.Toasty;
|
||||||
|
@ -209,6 +209,8 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
binding = ActivityPeertubeBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(binding.getRoot());
|
||||||
videoOrientationType = videoOrientation.LANDSCAPE;
|
videoOrientationType = videoOrientation.LANDSCAPE;
|
||||||
max_id = "0";
|
max_id = "0";
|
||||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||||
|
@ -306,7 +308,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
|
||||||
binding.webviewVideo.setVisibility(View.VISIBLE);
|
binding.webviewVideo.setVisibility(View.VISIBLE);
|
||||||
binding.mediaVideo.setVisibility(View.GONE);
|
binding.mediaVideo.setVisibility(View.GONE);
|
||||||
binding.doubleTapPlayerView.setVisibility(View.GONE);
|
binding.doubleTapPlayerView.setVisibility(View.GONE);
|
||||||
CustomWebview webview_video = Helper.initializeWebview(PeertubeActivity.this, R.id.webview_video, null);
|
WebView webview_video = Helper.initializeWebview(PeertubeActivity.this, R.id.webview_video, null);
|
||||||
|
|
||||||
MastalabWebChromeClient mastalabWebChromeClient = new MastalabWebChromeClient(PeertubeActivity.this, webview_video, binding.mainMediaFrame, binding.videoLayout);
|
MastalabWebChromeClient mastalabWebChromeClient = new MastalabWebChromeClient(PeertubeActivity.this, webview_video, binding.mainMediaFrame, binding.videoLayout);
|
||||||
mastalabWebChromeClient.setOnToggledFullscreen(fullscreen -> {
|
mastalabWebChromeClient.setOnToggledFullscreen(fullscreen -> {
|
||||||
|
@ -1940,35 +1942,45 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
|
||||||
private void initControllerButtons() {
|
private void initControllerButtons() {
|
||||||
|
|
||||||
PlayerControlView controlView = binding.doubleTapPlayerView.findViewById(R.id.exo_controller);
|
PlayerControlView controlView = binding.doubleTapPlayerView.findViewById(R.id.exo_controller);
|
||||||
|
if (controlView == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
fullScreenIcon = controlView.findViewById(R.id.exo_fullscreen_icon);
|
fullScreenIcon = controlView.findViewById(R.id.exo_fullscreen_icon);
|
||||||
View fullScreenButton = controlView.findViewById(R.id.exo_fullscreen_button);
|
View fullScreenButton = controlView.findViewById(R.id.exo_fullscreen_button);
|
||||||
fullScreenButton.setOnClickListener(v -> {
|
if (fullScreenButton != null) {
|
||||||
if (!fullScreenMode) {
|
fullScreenButton.setOnClickListener(v -> {
|
||||||
openFullscreenDialog();
|
if (!fullScreenMode) {
|
||||||
} else {
|
openFullscreenDialog();
|
||||||
closeFullscreenDialog();
|
} else {
|
||||||
setRequestedOrientationCustom(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
closeFullscreenDialog();
|
||||||
}
|
setRequestedOrientationCustom(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
ImageButton playButton = controlView.findViewById(R.id.exo_play);
|
ImageButton playButton = controlView.findViewById(R.id.exo_play);
|
||||||
playButton.setOnClickListener(v -> {
|
if (playButton != null) {
|
||||||
if (autoFullscreen && !fullScreenMode) {
|
playButton.setOnClickListener(v -> {
|
||||||
openFullscreenDialog();
|
if (autoFullscreen && !fullScreenMode) {
|
||||||
}
|
openFullscreenDialog();
|
||||||
player.setPlayWhenReady(true);
|
}
|
||||||
});
|
player.setPlayWhenReady(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
View exo_next = controlView.findViewById(R.id.exo_next);
|
View exo_next = controlView.findViewById(R.id.exo_next);
|
||||||
exo_next.setOnClickListener(v -> playNextVideo());
|
if (exo_next != null) {
|
||||||
|
exo_next.setOnClickListener(v -> playNextVideo());
|
||||||
|
}
|
||||||
|
|
||||||
View exoSettings = controlView.findViewById(R.id.exo_settings);
|
View exoSettings = controlView.findViewById(R.id.exo_settings);
|
||||||
exoSettings.setOnClickListener(v -> {
|
if (exoSettings != null) {
|
||||||
if (binding.videoParams.getVisibility() == View.VISIBLE) {
|
exoSettings.setOnClickListener(v -> {
|
||||||
closeMainMenuOptions();
|
if (binding.videoParams.getVisibility() == View.VISIBLE) {
|
||||||
} else {
|
closeMainMenuOptions();
|
||||||
openMainMenuOptions();
|
} else {
|
||||||
}
|
openMainMenuOptions();
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
import android.webkit.WebView;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
@ -37,7 +38,6 @@ import org.jetbrains.annotations.NotNull;
|
||||||
import app.fedilab.android.R;
|
import app.fedilab.android.R;
|
||||||
import app.fedilab.android.mastodon.activities.BaseBarActivity;
|
import app.fedilab.android.mastodon.activities.BaseBarActivity;
|
||||||
import app.fedilab.android.peertube.helper.Helper;
|
import app.fedilab.android.peertube.helper.Helper;
|
||||||
import app.fedilab.android.peertube.webview.CustomWebview;
|
|
||||||
import app.fedilab.android.peertube.webview.MastalabWebChromeClient;
|
import app.fedilab.android.peertube.webview.MastalabWebChromeClient;
|
||||||
import app.fedilab.android.peertube.webview.MastalabWebViewClient;
|
import app.fedilab.android.peertube.webview.MastalabWebViewClient;
|
||||||
import es.dmoral.toasty.Toasty;
|
import es.dmoral.toasty.Toasty;
|
||||||
|
@ -47,7 +47,7 @@ public class WebviewActivity extends BaseBarActivity {
|
||||||
|
|
||||||
private String url;
|
private String url;
|
||||||
private boolean peertubeLink;
|
private boolean peertubeLink;
|
||||||
private CustomWebview webView;
|
private WebView webView;
|
||||||
|
|
||||||
|
|
||||||
@SuppressLint("SetJavaScriptEnabled")
|
@SuppressLint("SetJavaScriptEnabled")
|
||||||
|
|
|
@ -177,19 +177,19 @@ public class RetrofitPeertubeAPI {
|
||||||
account.refresh_token = refresh_token;
|
account.refresh_token = refresh_token;
|
||||||
account.instance = instance;
|
account.instance = instance;
|
||||||
account.api = Account.API.PEERTUBE;
|
account.api = Account.API.PEERTUBE;
|
||||||
|
account.software = Account.API.PEERTUBE.name();
|
||||||
account.peertube_account = peertubeAccount;
|
account.peertube_account = peertubeAccount;
|
||||||
SQLiteDatabase db = Sqlite.getInstance(activity.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
account.user_id = peertubeAccount.getId();
|
||||||
boolean userExists = false;
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
|
editor.putString(PREF_USER_ID, account.user_id);
|
||||||
|
editor.putString(PREF_INSTANCE, host);
|
||||||
|
editor.putString(PREF_USER_TOKEN, token);
|
||||||
|
editor.apply();
|
||||||
try {
|
try {
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
||||||
editor.putString(PREF_USER_ID, account.user_id);
|
|
||||||
editor.putString(PREF_INSTANCE, host);
|
|
||||||
editor.apply();
|
|
||||||
new Account(activity).insertOrUpdate(account);
|
new Account(activity).insertOrUpdate(account);
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||||
Runnable myRunnable = () -> {
|
Runnable myRunnable = () -> {
|
||||||
Intent mainActivity = new Intent(activity, PeertubeMainActivity.class);
|
Intent mainActivity = new Intent(activity, PeertubeMainActivity.class);
|
||||||
|
@ -257,8 +257,6 @@ public class RetrofitPeertubeAPI {
|
||||||
SharedPreferences sharedpreferences = _context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
SharedPreferences sharedpreferences = _context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
editor.putString(PREF_USER_TOKEN, tokenReply.getAccess_token());
|
editor.putString(PREF_USER_TOKEN, tokenReply.getAccess_token());
|
||||||
editor.putString(Helper.PREF_SOFTWARE, null);
|
|
||||||
editor.putString(Helper.PREF_REMOTE_INSTANCE, null);
|
|
||||||
editor.apply();
|
editor.apply();
|
||||||
SQLiteDatabase db = Sqlite.getInstance(_context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
SQLiteDatabase db = Sqlite.getInstance(_context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||||
new Account(_context).updatePeertubeToken(tokenReply);
|
new Account(_context).updatePeertubeToken(tokenReply);
|
||||||
|
|
|
@ -46,6 +46,7 @@ import android.webkit.CookieManager;
|
||||||
import android.webkit.URLUtil;
|
import android.webkit.URLUtil;
|
||||||
import android.webkit.WebChromeClient;
|
import android.webkit.WebChromeClient;
|
||||||
import android.webkit.WebSettings;
|
import android.webkit.WebSettings;
|
||||||
|
import android.webkit.WebView;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
@ -83,7 +84,6 @@ import app.fedilab.android.peertube.client.data.ChannelData;
|
||||||
import app.fedilab.android.peertube.client.data.VideoData;
|
import app.fedilab.android.peertube.client.data.VideoData;
|
||||||
import app.fedilab.android.peertube.client.entities.File;
|
import app.fedilab.android.peertube.client.entities.File;
|
||||||
import app.fedilab.android.peertube.client.entities.PeertubeInformation;
|
import app.fedilab.android.peertube.client.entities.PeertubeInformation;
|
||||||
import app.fedilab.android.peertube.webview.CustomWebview;
|
|
||||||
import app.fedilab.android.peertube.webview.ProxyHelper;
|
import app.fedilab.android.peertube.webview.ProxyHelper;
|
||||||
import es.dmoral.toasty.Toasty;
|
import es.dmoral.toasty.Toasty;
|
||||||
import jp.wasabeef.glide.transformations.BlurTransformation;
|
import jp.wasabeef.glide.transformations.BlurTransformation;
|
||||||
|
@ -447,9 +447,9 @@ public class Helper {
|
||||||
* @return CustomWebview
|
* @return CustomWebview
|
||||||
*/
|
*/
|
||||||
@SuppressLint("SetJavaScriptEnabled")
|
@SuppressLint("SetJavaScriptEnabled")
|
||||||
public static CustomWebview initializeWebview(Activity activity, int webviewId, View rootView) {
|
public static WebView initializeWebview(Activity activity, int webviewId, View rootView) {
|
||||||
|
|
||||||
CustomWebview webView;
|
WebView webView;
|
||||||
if (rootView == null) {
|
if (rootView == null) {
|
||||||
webView = activity.findViewById(webviewId);
|
webView = activity.findViewById(webviewId);
|
||||||
} else {
|
} else {
|
||||||
|
@ -677,9 +677,9 @@ public class Helper {
|
||||||
}
|
}
|
||||||
AccountData.PeertubeAccount account = video.getAccount();
|
AccountData.PeertubeAccount account = video.getAccount();
|
||||||
ChannelData.Channel channel = video.getChannel();
|
ChannelData.Channel channel = video.getChannel();
|
||||||
if (account != null) {
|
if (account != null && account.getUserId() != null && account.getHost() != null) {
|
||||||
return account.getUserId().compareTo(userId) == 0 && account.getHost().compareTo(instance) == 0;
|
return account.getUserId().compareTo(userId) == 0 && account.getHost().compareTo(instance) == 0;
|
||||||
} else if (channel != null) {
|
} else if (channel != null && channel.getOwnerAccount() != null && channel.getOwnerAccount().getUserId() != null && channel.getOwnerAccount().getHost() != null) {
|
||||||
return channel.getOwnerAccount().getUserId().compareTo(userId) == 0 && channel.getHost().compareTo(instance) == 0;
|
return channel.getOwnerAccount().getUserId().compareTo(userId) == 0 && channel.getHost().compareTo(instance) == 0;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1,53 +0,0 @@
|
||||||
package app.fedilab.android.peertube.webview;
|
|
||||||
/* Copyright 2020 Thomas Schneider
|
|
||||||
*
|
|
||||||
* This file is a part of TubeLab
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* TubeLab 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 TubeLab; if not,
|
|
||||||
* see <http://www.gnu.org/licenses>. */
|
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.res.Configuration;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.util.AttributeSet;
|
|
||||||
import android.webkit.WebView;
|
|
||||||
|
|
||||||
|
|
||||||
public class CustomWebview extends WebView {
|
|
||||||
|
|
||||||
|
|
||||||
public CustomWebview(Context context) {
|
|
||||||
super(getFixedContext(context));
|
|
||||||
}
|
|
||||||
|
|
||||||
public CustomWebview(Context context, AttributeSet attrs) {
|
|
||||||
super(getFixedContext(context), attrs);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CustomWebview(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
||||||
super(getFixedContext(context), attrs, defStyleAttr);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
|
||||||
public CustomWebview(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
|
||||||
super(getFixedContext(context), attrs, defStyleAttr, defStyleRes);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public CustomWebview(Context context, AttributeSet attrs, int defStyleAttr, boolean privateBrowsing) {
|
|
||||||
super(getFixedContext(context), attrs, defStyleAttr, privateBrowsing);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Context getFixedContext(Context context) {
|
|
||||||
return context.createConfigurationContext(new Configuration());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -37,7 +37,7 @@ import app.fedilab.android.R;
|
||||||
|
|
||||||
public class MastalabWebChromeClient extends WebChromeClient implements MediaPlayer.OnCompletionListener, MediaPlayer.OnErrorListener {
|
public class MastalabWebChromeClient extends WebChromeClient implements MediaPlayer.OnCompletionListener, MediaPlayer.OnErrorListener {
|
||||||
|
|
||||||
private final CustomWebview webView;
|
private final WebView webView;
|
||||||
private final View activityNonVideoView;
|
private final View activityNonVideoView;
|
||||||
private final ViewGroup activityVideoView;
|
private final ViewGroup activityVideoView;
|
||||||
private final ProgressBar pbar;
|
private final ProgressBar pbar;
|
||||||
|
@ -48,7 +48,7 @@ public class MastalabWebChromeClient extends WebChromeClient implements MediaPla
|
||||||
private boolean isVideoFullscreen;
|
private boolean isVideoFullscreen;
|
||||||
|
|
||||||
|
|
||||||
public MastalabWebChromeClient(Activity activity, CustomWebview webView, FrameLayout activityNonVideoView, ViewGroup activityVideoView) {
|
public MastalabWebChromeClient(Activity activity, WebView webView, FrameLayout activityNonVideoView, ViewGroup activityVideoView) {
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
this.isVideoFullscreen = false;
|
this.isVideoFullscreen = false;
|
||||||
this.webView = webView;
|
this.webView = webView;
|
||||||
|
|
|
@ -19,6 +19,7 @@ import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Proxy;
|
import android.net.Proxy;
|
||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
|
import android.webkit.WebView;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
@ -28,14 +29,14 @@ import java.lang.reflect.Method;
|
||||||
public class ProxyHelper {
|
public class ProxyHelper {
|
||||||
|
|
||||||
|
|
||||||
public static void setProxy(Context context, CustomWebview webview, String host, int port, String applicationClassName) {
|
public static void setProxy(Context context, WebView webview, String host, int port, String applicationClassName) {
|
||||||
|
|
||||||
setProxyKKPlus(context, webview, host, port, applicationClassName);
|
setProxyKKPlus(context, webview, host, port, applicationClassName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("all")
|
@SuppressWarnings("all")
|
||||||
private static boolean setProxyICS(CustomWebview webview, String host, int port) {
|
private static boolean setProxyICS(WebView webview, String host, int port) {
|
||||||
try {
|
try {
|
||||||
Class jwcjb = Class.forName("android.webkit.JWebCoreJavaBridge");
|
Class jwcjb = Class.forName("android.webkit.JWebCoreJavaBridge");
|
||||||
Class params[] = new Class[1];
|
Class params[] = new Class[1];
|
||||||
|
@ -72,7 +73,7 @@ public class ProxyHelper {
|
||||||
* Set Proxy for Android 4.1 - 4.3.
|
* Set Proxy for Android 4.1 - 4.3.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("all")
|
@SuppressWarnings("all")
|
||||||
private static boolean setProxyJB(CustomWebview webview, String host, int port) {
|
private static boolean setProxyJB(WebView webview, String host, int port) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Class wvcClass = Class.forName("android.webkit.WebViewClassic");
|
Class wvcClass = Class.forName("android.webkit.WebViewClassic");
|
||||||
|
@ -115,7 +116,7 @@ public class ProxyHelper {
|
||||||
// from https://stackoverflow.com/questions/19979578/android-webview-set-proxy-programatically-kitkat
|
// from https://stackoverflow.com/questions/19979578/android-webview-set-proxy-programatically-kitkat
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
@SuppressWarnings("all")
|
@SuppressWarnings("all")
|
||||||
private static void setProxyKKPlus(Context appContext, CustomWebview webView, String host, int port, String applicationClassName) {
|
private static void setProxyKKPlus(Context appContext, WebView webView, String host, int port, String applicationClassName) {
|
||||||
|
|
||||||
System.setProperty("http.proxyHost", host);
|
System.setProperty("http.proxyHost", host);
|
||||||
System.setProperty("http.proxyPort", port + "");
|
System.setProperty("http.proxyPort", port + "");
|
||||||
|
|
|
@ -80,7 +80,7 @@
|
||||||
android:id="@+id/min_controller"
|
android:id="@+id/min_controller"
|
||||||
layout="@layout/min_controller" />
|
layout="@layout/min_controller" />
|
||||||
|
|
||||||
<app.fedilab.android.peertube.webview.CustomWebview
|
<WebView
|
||||||
android:id="@+id/webview_video"
|
android:id="@+id/webview_video"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
@ -382,7 +382,7 @@
|
||||||
android:id="@+id/video_params"
|
android:id="@+id/video_params"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="?backgroundColor"
|
android:background="?android:windowBackground"
|
||||||
android:minHeight="100dp"
|
android:minHeight="100dp"
|
||||||
android:translationZ="2dp"
|
android:translationZ="2dp"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
|
@ -571,7 +571,7 @@
|
||||||
android:id="@+id/video_params_submenu"
|
android:id="@+id/video_params_submenu"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="?backgroundColor"
|
android:background="?android:colorBackground"
|
||||||
android:minHeight="300dp"
|
android:minHeight="300dp"
|
||||||
android:translationZ="3dp"
|
android:translationZ="3dp"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_weight="1">
|
android:layout_weight="1">
|
||||||
|
|
||||||
<app.fedilab.android.peertube.webview.CustomWebview
|
<WebView
|
||||||
android:id="@+id/webview"
|
android:id="@+id/webview"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
|
Loading…
Reference in a new issue