Commit 493b173e authored by Geoffrey Métais's avatar Geoffrey Métais

Reduce VLCApplication.getAppConstext() usage

parent c560216a
......@@ -1182,7 +1182,7 @@ class PlaybackService : MediaBrowserServiceCompat() {
fun setRenderer(item: RendererItem?) {
val wasOnRenderer = hasRenderer()
if (wasOnRenderer && !hasRenderer() && canSwitchToVideo())
VideoPlayerActivity.startOpened(VLCApplication.getAppContext(),
VideoPlayerActivity.startOpened(applicationContext,
playlistManager.getCurrentMedia()!!.uri, playlistManager.currentIndex)
playlistManager.setRenderer(item)
if (!wasOnRenderer && item != null) audioFocusHelper.changeAudioFocus(false)
......
......@@ -383,9 +383,9 @@ public class EqualizerFragment extends AppCompatDialogFragment implements Playba
public void onClick(View view) {
final String newName = input.getText().toString();
if (newName.contains("_") || TextUtils.equals(newName, newPresetName)) {
Toast.makeText(VLCApplication.getAppContext(), VLCApplication.getAppContext().getResources().getString(R.string.custom_set_wrong_input), Toast.LENGTH_SHORT).show();
Toast.makeText(context, VLCApplication.getAppContext().getResources().getString(R.string.custom_set_wrong_input), Toast.LENGTH_SHORT).show();
} else if (allSets.contains(newName) && !TextUtils.equals(newName,oldName)) {
Toast.makeText(VLCApplication.getAppContext(), VLCApplication.getAppContext().getResources().getString(R.string.custom_set_already_exist), Toast.LENGTH_SHORT).show();
Toast.makeText(context, VLCApplication.getAppContext().getResources().getString(R.string.custom_set_already_exist), Toast.LENGTH_SHORT).show();
} else {
VLCOptions.saveCustomSet(context, temporarySet, newName);
if (onPause) {
......
......@@ -182,12 +182,12 @@ public class AdvOptionsDialog extends DismissDialogFragment implements View.OnCl
mAdapter = new AdvOptionsAdapter();
mRecyclerView.setAdapter(mAdapter);
mToast = Toast.makeText(VLCApplication.getAppContext(), "", Toast.LENGTH_SHORT);
mToast = Toast.makeText(mRecyclerView.getContext(), "", Toast.LENGTH_SHORT);
mToast.setGravity(Gravity.TOP,0,100);
//Get default color
final int[] attrs = new int[] { android.R.attr.textColorSecondary };
final TypedArray a = getActivity().getTheme().obtainStyledAttributes(R.style.Theme_VLC, attrs);
final TypedArray a = mRecyclerView.getContext().getTheme().obtainStyledAttributes(R.style.Theme_VLC, attrs);
mTextColor = a.getColor(0, Color.LTGRAY);
a.recycle();
......
......@@ -36,7 +36,6 @@ import android.widget.EditText;
import org.videolan.libvlc.Dialog;
import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.databinding.VlcLoginDialogBinding;
import org.videolan.vlc.gui.helpers.UiTools;
import org.videolan.vlc.gui.preferences.PreferencesActivity;
......@@ -81,13 +80,12 @@ public class VlcLoginDialog extends VlcDialog<Dialog.LoginDialog, VlcLoginDialog
@Override
public void onFocusChange(final View v, boolean hasFocus) {
if (hasFocus)
UiTools.setKeyboardVisibility(v, v instanceof EditText);
if (hasFocus) UiTools.setKeyboardVisibility(v, v instanceof EditText);
}
@Override
public void onDestroy() {
LocalBroadcastManager.getInstance(VLCApplication.getAppContext()).sendBroadcast(new Intent(ACTION_DIALOG_CANCELED));
LocalBroadcastManager.getInstance(requireContext()).sendBroadcast(new Intent(ACTION_DIALOG_CANCELED));
super.onDestroy();
}
}
......@@ -15,7 +15,6 @@ import android.widget.ImageView
import android.widget.TextView
import kotlinx.coroutines.experimental.*
import kotlinx.coroutines.experimental.android.Main
import kotlinx.coroutines.experimental.android.UI
import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.medialibrary.media.MediaWrapper
import org.videolan.vlc.BR
......@@ -86,7 +85,7 @@ fun updateImageView(bitmap: Bitmap?, target: View, vdb: ViewDataBinding?) {
target.visibility = View.VISIBLE
}
is TextView -> {
ViewCompat.setBackground(target, BitmapDrawable(VLCApplication.getAppResources(), bitmap))
ViewCompat.setBackground(target, BitmapDrawable(target.context.resources, bitmap))
target.text = null
}
is ImageCardView -> {
......
......@@ -84,6 +84,7 @@ import org.videolan.vlc.media.MediaUtils;
import org.videolan.vlc.util.Constants;
import org.videolan.vlc.util.FileUtils;
import org.videolan.vlc.util.LocalePair;
import org.videolan.vlc.util.Settings;
import org.videolan.vlc.viewmodels.SortableModel;
import java.util.List;
......@@ -181,7 +182,7 @@ public class UiTools {
* @return the color id
*/
public static int getColorFromAttribute(Context context, int attrId) {
return VLCApplication.getAppResources().getColor(getResourceFromAttribute(context, attrId));
return context.getResources().getColor(getResourceFromAttribute(context, attrId));
}
/**
* Set the alignment mode of the specified TextView with the desired align
......@@ -219,23 +220,23 @@ public class UiTools {
if (v != null) v.setOnClickListener(ocl);
}
public static boolean isBlackThemeEnabled() {
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
public static boolean isBlackThemeEnabled(Context context) {
final SharedPreferences pref = Settings.INSTANCE.getInstance(context);
return pref.getBoolean("enable_black_theme", false);
}
public static void fillAboutView(View v) {
final TextView link = v.findViewById(R.id.main_link);
link.setText(Html.fromHtml(VLCApplication.getAppResources().getString(R.string.about_link)));
link.setText(Html.fromHtml(v.getContext().getString(R.string.about_link)));
final String revision = VLCApplication.getAppResources().getString(R.string.build_revision)+" VLC: "+VLCApplication.getAppResources().getString(R.string.build_vlc_revision);
final String builddate = VLCApplication.getAppResources().getString(R.string.build_time);
final String builder = VLCApplication.getAppResources().getString(R.string.build_host);
final String revision = v.getContext().getString(R.string.build_revision)+" VLC: "+v.getContext().getString(R.string.build_vlc_revision);
final String builddate = v.getContext().getString(R.string.build_time);
final String builder = v.getContext().getString(R.string.build_host);
final TextView compiled = v.findViewById(R.id.main_compiled);
compiled.setText(builder + " (" + builddate + ")");
final TextView textview_rev = v.findViewById(R.id.main_revision);
textview_rev.setText(VLCApplication.getAppResources().getString(R.string.revision) + " " + revision + " (" + builddate + ") " + BuildConfig.FLAVOR_abi);
textview_rev.setText(v.getContext().getString(R.string.revision) + " " + revision + " (" + builddate + ") " + BuildConfig.FLAVOR_abi);
final ImageView logo = v.findViewById(R.id.logo);
logo.setOnClickListener(new View.OnClickListener() {
......@@ -403,7 +404,7 @@ public class UiTools {
})
.setNegativeButton(R.string.ml_external_storage_decline, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext())
Settings.INSTANCE.getInstance(activity)
.edit()
.putBoolean("ignore_"+ uuid, true)
.apply();
......@@ -424,7 +425,7 @@ public class UiTools {
})
.setNegativeButton(R.string.ml_external_storage_decline, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext())
Settings.INSTANCE.getInstance(activity)
.edit()
.putBoolean("ignore_"+ uuid, true)
.apply();
......
......@@ -18,6 +18,7 @@ import org.videolan.vlc.R
import org.videolan.vlc.VLCApplication
import org.videolan.vlc.util.AndroidDevices
import org.videolan.vlc.util.FileUtils
import org.videolan.vlc.util.Settings
class WriteExternalDelegate : BaseHeadlessFragment() {
......@@ -58,8 +59,9 @@ class WriteExternalDelegate : BaseHeadlessFragment() {
if (resultCode == Activity.RESULT_OK) {
val context = context ?: return
val treeUri = data.data
PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext()).edit()
.putString("tree_uri_$storage", treeUri.toString()).apply()
Settings.getInstance(context).edit()
.putString("tree_uri_$storage", treeUri.toString())
.apply()
val treeFile = DocumentFile.fromTreeUri(context, treeUri)
val contentResolver = context.contentResolver
......
......@@ -76,7 +76,7 @@ public class PreferencesAdvanced extends BasePreferenceFragment implements Share
return false;
switch (preference.getKey()){
case "debug_logs":
Intent intent = new Intent(VLCApplication.getAppContext(), DebugLogActivity.class);
final Intent intent = new Intent(requireContext(), DebugLogActivity.class);
startActivity(intent);
return true;
case "clear_history":
......@@ -97,7 +97,7 @@ public class PreferencesAdvanced extends BasePreferenceFragment implements Share
case "clear_media_db":
final Intent i = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
i.addCategory(Intent.CATEGORY_DEFAULT);
i.setData(Uri.parse("package:" + VLCApplication.getAppContext().getPackageName()));
i.setData(Uri.parse("package:" + requireContext().getPackageName()));
startActivity(i);
return true;
case "quit_app":
......@@ -106,26 +106,27 @@ public class PreferencesAdvanced extends BasePreferenceFragment implements Share
case "dump_media_db":
if (VLCApplication.getMLInstance().isWorking())
UiTools.snacker(getView(), getString(R.string.settings_ml_block_scan));
else {
WorkersKt.runIO(new Runnable() {
else WorkersKt.runIO(new Runnable() {
@Override
public void run() {
final Runnable dump = new Runnable() {
@Override
public void run() {
final File db = new File(VLCApplication.getAppContext().getDir("db", Context.MODE_PRIVATE)+ Medialibrary.VLC_MEDIA_DB_NAME);
final File db = new File(requireContext().getDir("db", Context.MODE_PRIVATE)+ Medialibrary.VLC_MEDIA_DB_NAME);
if (FileUtils.copyFile(db, new File(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY + Medialibrary.VLC_MEDIA_DB_NAME)))
WorkersKt.runOnMainThread(new Runnable() {
@Override
public void run() {
Toast.makeText(VLCApplication.getAppContext(), "Database dumped on internal storage root", Toast.LENGTH_LONG).show();
final Context ctx = getContext();
if (ctx != null) Toast.makeText(ctx, "Database dumped on internal storage root", Toast.LENGTH_LONG).show();
}
});
else WorkersKt.runOnMainThread(new Runnable() {
@Override
public void run() {
Toast.makeText(VLCApplication.getAppContext(), "Failed to dumped database", Toast.LENGTH_LONG).show();
final Context ctx = getContext();
if (ctx != null) Toast.makeText(ctx, "Failed to dumped database", Toast.LENGTH_LONG).show();
}
});
}
......@@ -134,7 +135,6 @@ public class PreferencesAdvanced extends BasePreferenceFragment implements Share
else Permissions.askWriteStoragePermission(getActivity(), false, dump);
}
});
}
return true;
}
return super.onPreferenceTreeClick(preference);
......
......@@ -45,7 +45,6 @@ import org.videolan.libvlc.util.AndroidUtil;
import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.vlc.PlaybackService;
import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.gui.PlaybackServiceFragment;
import org.videolan.vlc.gui.helpers.AudioUtil;
import org.videolan.vlc.gui.helpers.UiTools;
......@@ -149,7 +148,7 @@ public class MediaItemDetailsFragment extends DetailsSupportFragment implements
detailsOverview.removeAction(actionAdd);
detailsOverview.addAction(actionDelete);
mRowsAdapter.notifyArrayItemRangeChanged(0, mRowsAdapter.size());
Toast.makeText(VLCApplication.getAppContext(), R.string.favorite_added, Toast.LENGTH_SHORT).show();
Toast.makeText(activity, R.string.favorite_added, Toast.LENGTH_SHORT).show();
break;
case ID_FAVORITE_DELETE:
WorkersKt.runIO(new Runnable() {
......@@ -161,7 +160,7 @@ public class MediaItemDetailsFragment extends DetailsSupportFragment implements
detailsOverview.removeAction(actionDelete);
detailsOverview.addAction(actionAdd);
mRowsAdapter.notifyArrayItemRangeChanged(0, mRowsAdapter.size());
Toast.makeText(VLCApplication.getAppContext(), R.string.favorite_removed, Toast.LENGTH_SHORT).show();
Toast.makeText(activity, R.string.favorite_removed, Toast.LENGTH_SHORT).show();
break;
case ID_BROWSE:
TvUtil.INSTANCE.openMedia(activity, media, null);
......
......@@ -38,7 +38,6 @@ import android.text.TextUtils
import android.view.View
import kotlinx.coroutines.experimental.*
import kotlinx.coroutines.experimental.android.Main
import kotlinx.coroutines.experimental.android.UI
import org.videolan.medialibrary.media.DummyItem
import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.medialibrary.media.MediaWrapper
......
......@@ -25,6 +25,7 @@ package org.videolan.vlc.gui.tv.preferences;
import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
......@@ -67,11 +68,11 @@ public class PreferencesAdvanced extends BasePreferenceFragment implements Share
@Override
public boolean onPreferenceTreeClick(Preference preference) {
if (preference.getKey() == null)
return false;
switch (preference.getKey()){
final Context ctx = getActivity();
if (preference.getKey() == null || ctx == null) return false;
switch (preference.getKey()) {
case "debug_logs":
Intent intent = new Intent(VLCApplication.getAppContext(), DebugLogActivity.class);
Intent intent = new Intent(ctx, DebugLogActivity.class);
startActivity(intent);
return true;
case "clear_history":
......@@ -89,9 +90,9 @@ public class PreferencesAdvanced extends BasePreferenceFragment implements Share
.setNegativeButton(android.R.string.cancel, null).show();
return true;
case "clear_media_db":
Intent i = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
final Intent i = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
i.addCategory(Intent.CATEGORY_DEFAULT);
i.setData(Uri.parse("package:" + VLCApplication.getAppContext().getPackageName()));
i.setData(Uri.parse("package:" + ctx.getPackageName()));
startActivity(i);
return true;
case "quit_app":
......
......@@ -47,7 +47,6 @@ import org.videolan.libvlc.MediaPlayer;
import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.vlc.PlaybackService;
import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.gui.preferences.PreferencesActivity;
import org.videolan.vlc.gui.view.PopupLayout;
import org.videolan.vlc.util.Constants;
......@@ -88,10 +87,10 @@ public class PopupManager implements PlaybackService.Callback, GestureDetector.O
public void showPopup() {
mService.addCallback(this);
LayoutInflater li = (LayoutInflater) VLCApplication.getAppContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final LayoutInflater li = (LayoutInflater) mService.getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (li == null) return;
mRootView = (PopupLayout) li.inflate(R.layout.video_popup, null);
if (mAlwaysOn)
mRootView.setKeepScreenOn(true);
if (mAlwaysOn) mRootView.setKeepScreenOn(true);
mPlayPauseButton = mRootView.findViewById(R.id.video_play_pause);
mCloseButton = mRootView.findViewById(R.id.popup_close);
mExpandButton = mRootView.findViewById(R.id.popup_expand);
......@@ -104,6 +103,7 @@ public class PopupManager implements PlaybackService.Callback, GestureDetector.O
mRootView.setGestureDetector(gestureDetector);
final IVLCVout vlcVout = mService.getVout();
if (vlcVout == null) return;
vlcVout.setVideoView((SurfaceView) mRootView.findViewById(R.id.player_surface));
vlcVout.addCallback(this);
vlcVout.attachViews(this);
......@@ -112,8 +112,7 @@ public class PopupManager implements PlaybackService.Callback, GestureDetector.O
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
if (mPlayPauseButton.getVisibility() == View.VISIBLE)
return false;
if (mPlayPauseButton.getVisibility() == View.VISIBLE) return false;
mHandler.sendEmptyMessage(SHOW_BUTTONS);
mHandler.sendEmptyMessageDelayed(HIDE_BUTTONS, MSG_DELAY);
return true;
......@@ -191,10 +190,8 @@ public class PopupManager implements PlaybackService.Callback, GestureDetector.O
// compute the display aspect ratio
double dar = dw / dh;
if (dar < ar)
dh = dw / ar;
else
dw = dh * ar;
if (dar < ar) dh = dw / ar;
else dw = dh * ar;
width = (int) Math.floor(dw);
height = (int) Math.floor(dh);
......
......@@ -50,7 +50,6 @@ import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.tools.MultiSelectHelper;
import org.videolan.vlc.MediaParsingServiceKt;
import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.databinding.VideoGridBinding;
import org.videolan.vlc.gui.MainActivity;
import org.videolan.vlc.gui.SecondaryActivity;
......@@ -371,7 +370,7 @@ public class VideoGridFragment extends MediaBrowserFragment<VideosModel> impleme
}
public void updateSeenMediaMarker() {
mAdapter.setSeenMediaMarkerVisible(PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext()).getBoolean("media_seen", true));
mAdapter.setSeenMediaMarkerVisible(Settings.INSTANCE.getInstance(requireContext()).getBoolean("media_seen", true));
mAdapter.notifyItemRangeChanged(0, mAdapter.getItemCount()-1, Constants.UPDATE_SEEN);
}
......
......@@ -854,7 +854,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
@NonNull
public static Intent getIntent(String action, Context context, Uri uri, String title, boolean fromStart, int openedPosition) {
Intent intent = new Intent(context, VideoPlayerActivity.class);
final Intent intent = new Intent(context, VideoPlayerActivity.class);
intent.setAction(action);
intent.putExtra(Constants.PLAY_EXTRA_ITEM_LOCATION, uri);
intent.putExtra(Constants.PLAY_EXTRA_ITEM_TITLE, title);
......
......@@ -116,8 +116,8 @@ public class PopupLayout extends RelativeLayout implements ScaleGestureDetector.
private void init(Context context) {
mWindowManager = (WindowManager) context.getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
mPopupWidth = VLCApplication.getAppResources().getDimensionPixelSize(R.dimen.video_pip_width);
mPopupHeight = VLCApplication.getAppResources().getDimensionPixelSize(R.dimen.video_pip_heigth);
mPopupWidth = context.getResources().getDimensionPixelSize(R.dimen.video_pip_width);
mPopupHeight = context.getResources().getDimensionPixelSize(R.dimen.video_pip_heigth);
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
mPopupWidth,
mPopupHeight,
......
......@@ -37,7 +37,6 @@ import android.widget.RemoteViews;
import org.videolan.vlc.BuildConfig;
import org.videolan.vlc.R;
import org.videolan.vlc.StartActivity;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.gui.helpers.AudioUtil;
import org.videolan.vlc.util.Strings;
import org.videolan.vlc.util.WorkersKt;
......@@ -87,7 +86,7 @@ abstract public class VLCAppWidgetProvider extends AppWidgetProvider {
final Intent iPlay = new Intent(ACTION_REMOTE_PLAYPAUSE);
final Intent iStop = new Intent(ACTION_REMOTE_STOP);
final Intent iForward = new Intent(ACTION_REMOTE_FORWARD);
final Intent iVlc = new Intent(VLCApplication.getAppContext(), StartActivity.class);
final Intent iVlc = new Intent(context, StartActivity.class);
final PendingIntent piBackward = PendingIntent.getBroadcast(context, 0, iBackward, PendingIntent.FLAG_UPDATE_CURRENT);
final PendingIntent piPlay = PendingIntent.getBroadcast(context, 0, iPlay, PendingIntent.FLAG_UPDATE_CURRENT);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment