diff --git a/serenity-app/src/main/java/us/nineworlds/serenity/AboutDialog.java b/serenity-app/src/main/java/us/nineworlds/serenity/AboutDialog.java deleted file mode 100644 index f17c01260..000000000 --- a/serenity-app/src/main/java/us/nineworlds/serenity/AboutDialog.java +++ /dev/null @@ -1,65 +0,0 @@ -package us.nineworlds.serenity; - -import android.app.Dialog; -import android.content.Context; -import android.content.pm.PackageManager.NameNotFoundException; -import android.graphics.Color; -import android.os.Bundle; -import android.text.Html; -import android.text.method.ScrollingMovementMethod; -import android.widget.TextView; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; - -public class AboutDialog extends Dialog { - private Context mContext = null; - - public AboutDialog(Context context) { - super(context); - mContext = context; - } - - @Override public void onCreate(Bundle savedInstanceState) { - setContentView(R.layout.about); - TextView tv = (TextView) findViewById(R.id.legal_text); - tv.setText(Html.fromHtml(readRawTextFile(R.raw.legal))); - tv.setMovementMethod(new ScrollingMovementMethod()); - - tv = (TextView) findViewById(R.id.info_text); - tv.setText(Html.fromHtml(readRawTextFile(R.raw.info))); - tv.setLinkTextColor(Color.WHITE); - String versionName; - try { - versionName = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0).versionName; - } catch (NameNotFoundException e) { - versionName = ""; - } - setTitle(mContext.getString(R.string.about_title_serenity_for_google_tv) + " v" + versionName); - } - - public String readRawTextFile(int id) { - InputStream inputStream = mContext.getResources().openRawResource(id); - InputStreamReader in = new InputStreamReader(inputStream); - BufferedReader buf = new BufferedReader(in); - String line; - StringBuilder text = new StringBuilder(); - try { - while ((line = buf.readLine()) != null) { - text.append(line); - } - } catch (IOException e) { - return null; - } finally { - try { - buf.close(); - in.close(); - inputStream.close(); - } catch (IOException e) { - } - } - return text.toString(); - } -} \ No newline at end of file diff --git a/serenity-app/src/main/java/us/nineworlds/serenity/recyclerutils/GridSpacingItemDecoration.java b/serenity-app/src/main/java/us/nineworlds/serenity/recyclerutils/GridSpacingItemDecoration.java deleted file mode 100644 index 162208005..000000000 --- a/serenity-app/src/main/java/us/nineworlds/serenity/recyclerutils/GridSpacingItemDecoration.java +++ /dev/null @@ -1,45 +0,0 @@ -package us.nineworlds.serenity.recyclerutils; - -import android.graphics.Rect; -import android.view.View; - -import androidx.recyclerview.widget.RecyclerView; - -public class GridSpacingItemDecoration extends RecyclerView.ItemDecoration { - - private int spanCount; - private int spacing; - private boolean includeEdge; - - public GridSpacingItemDecoration(int spanCount, int spacing, boolean includeEdge) { - this.spanCount = spanCount; - this.spacing = spacing; - this.includeEdge = includeEdge; - } - - @Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, - RecyclerView.State state) { - int position = parent.getChildAdapterPosition(view); // item position - int column = position % spanCount; // item column - - if (includeEdge) { - outRect.left = - spacing - column * spacing / spanCount; // spacing - column * ((1f / spanCount) * spacing) - outRect.right = - (column + 1) * spacing / spanCount; // (column + 1) * ((1f / spanCount) * spacing) - - if (position < spanCount) { // top edge - outRect.top = spacing; - } - outRect.bottom = spacing; // item bottom - } else { - outRect.left = column * spacing / spanCount; // column * ((1f / spanCount) * spacing) - outRect.right = spacing - - (column + 1) * spacing - / spanCount; // spacing - (column + 1) * ((1f / spanCount) * spacing) - if (position >= spanCount) { - outRect.top = spacing; // item top - } - } - } -} \ No newline at end of file diff --git a/serenity-app/src/main/java/us/nineworlds/serenity/recyclerutils/ItemOffsetDecoration.java b/serenity-app/src/main/java/us/nineworlds/serenity/recyclerutils/ItemOffsetDecoration.java deleted file mode 100644 index e7107a184..000000000 --- a/serenity-app/src/main/java/us/nineworlds/serenity/recyclerutils/ItemOffsetDecoration.java +++ /dev/null @@ -1,28 +0,0 @@ -package us.nineworlds.serenity.recyclerutils; - -import android.content.Context; -import android.graphics.Rect; -import android.view.View; - -import androidx.annotation.DimenRes; -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.RecyclerView; - -public class ItemOffsetDecoration extends RecyclerView.ItemDecoration { - - private int mItemOffset; - - public ItemOffsetDecoration(int itemOffset) { - mItemOffset = itemOffset; - } - - public ItemOffsetDecoration(@NonNull Context context, @DimenRes int itemOffsetId) { - this(context.getResources().getDimensionPixelSize(itemOffsetId)); - } - - @Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, - RecyclerView.State state) { - super.getItemOffsets(outRect, view, parent, state); - outRect.set(mItemOffset, mItemOffset, mItemOffset, mItemOffset); - } -} \ No newline at end of file diff --git a/serenity-app/src/main/java/us/nineworlds/serenity/recyclerutils/SpaceItemDecoration.java b/serenity-app/src/main/java/us/nineworlds/serenity/recyclerutils/SpaceItemDecoration.java deleted file mode 100644 index a4fcb491e..000000000 --- a/serenity-app/src/main/java/us/nineworlds/serenity/recyclerutils/SpaceItemDecoration.java +++ /dev/null @@ -1,66 +0,0 @@ -package us.nineworlds.serenity.recyclerutils; - -import android.graphics.Rect; -import android.view.View; - -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -public class SpaceItemDecoration extends RecyclerView.ItemDecoration { - private static final boolean DEFAULT_ADD_SPACE_ABOVE_FIRST_ITEM = false; - private static final boolean DEFAULT_ADD_SPACE_BELOW_LAST_ITEM = false; - - private final int space; - private final boolean addSpaceAboveFirstItem; - private final boolean addSpaceBelowLastItem; - - public SpaceItemDecoration(int space) { - this(space, DEFAULT_ADD_SPACE_ABOVE_FIRST_ITEM, DEFAULT_ADD_SPACE_BELOW_LAST_ITEM); - } - - public SpaceItemDecoration(int space, boolean addSpaceAboveFirstItem, - boolean addSpaceBelowLastItem) { - this.space = space; - this.addSpaceAboveFirstItem = addSpaceAboveFirstItem; - this.addSpaceBelowLastItem = addSpaceBelowLastItem; - } - - @Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, - RecyclerView.State state) { - super.getItemOffsets(outRect, view, parent, state); - if (space <= 0) { - return; - } - - if (addSpaceAboveFirstItem && parent.getChildLayoutPosition(view) < 1 - || parent.getChildLayoutPosition(view) >= 1) { - if (getOrientation(parent) == LinearLayoutManager.VERTICAL) { - outRect.top = space; - } else { - outRect.left = space; - } - } - - if (addSpaceBelowLastItem - && parent.getChildAdapterPosition(view) == getTotalItemCount(parent) - 1) { - if (getOrientation(parent) == LinearLayoutManager.VERTICAL) { - outRect.bottom = space; - } else { - outRect.right = space; - } - } - } - - private int getTotalItemCount(RecyclerView parent) { - return parent.getAdapter().getItemCount(); - } - - private int getOrientation(RecyclerView parent) { - if (parent.getLayoutManager() instanceof LinearLayoutManager) { - return ((LinearLayoutManager) parent.getLayoutManager()).getOrientation(); - } else { - throw new IllegalStateException( - "SpaceItemDecoration can only be used with a LinearLayoutManager."); - } - } -} \ No newline at end of file diff --git a/serenity-app/src/main/java/us/nineworlds/serenity/ui/activity/SerenityMultiViewVideoActivity.java b/serenity-app/src/main/java/us/nineworlds/serenity/ui/activity/SerenityMultiViewVideoActivity.java deleted file mode 100644 index b1e65b0a9..000000000 --- a/serenity-app/src/main/java/us/nineworlds/serenity/ui/activity/SerenityMultiViewVideoActivity.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * The MIT License (MIT) - * Copyright (c) 2012 David Carver - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - *

- * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS - * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF - * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package us.nineworlds.serenity.ui.activity; - -/** - * A activity that handles the indicator of whether toggling between Grid and - * Detail view should occur. Views that need to support Detail and Grid view - * should extend this view. - * - * @author dcarver - */ -public abstract class SerenityMultiViewVideoActivity extends SerenityVideoActivity { - - protected boolean gridViewActive = false; - - @Override public void finish() { - super.finish(); - } - - protected boolean posterLayoutActive = false; - - public boolean isGridViewActive() { - return gridViewActive; - } - - /** - * Used to indicate whether posters or banners are shown. - */ - public boolean isPosterLayoutActive() { - return posterLayoutActive; - } - - public void setGridViewEnabled(boolean sw) { - gridViewActive = sw; - } - - public void setPosterLayoutActive(boolean sw) { - posterLayoutActive = sw; - } -} diff --git a/serenity-app/src/main/java/us/nineworlds/serenity/ui/adapters/RecyclerViewDiffUtil.kt b/serenity-app/src/main/java/us/nineworlds/serenity/ui/adapters/RecyclerViewDiffUtil.kt deleted file mode 100644 index 808a45c18..000000000 --- a/serenity-app/src/main/java/us/nineworlds/serenity/ui/adapters/RecyclerViewDiffUtil.kt +++ /dev/null @@ -1,21 +0,0 @@ -package us.nineworlds.serenity.ui.adapters - -import androidx.recyclerview.widget.DiffUtil -import us.nineworlds.serenity.core.model.ContentInfo - -class RecyclerViewDiffUtil(private val oldList: List?, private val newList: List) : DiffUtil.Callback() { - override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean = - oldList!![oldItemPosition].id() == newList[newItemPosition].id() - - override fun getOldListSize(): Int = oldList?.size ?: 0 - - override fun getNewListSize(): Int = newList.size - - override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean = - oldList!![oldItemPosition] == newList[newItemPosition] - - fun dispatchUpdatesTo(adapter: androidx.recyclerview.widget.RecyclerView.Adapter<*>) { - val diffResult = DiffUtil.calculateDiff(this) - diffResult.dispatchUpdatesTo(adapter) - } -} \ No newline at end of file diff --git a/serenity-app/src/main/java/us/nineworlds/serenity/ui/dialogs/DirectoryChooserDialog.java b/serenity-app/src/main/java/us/nineworlds/serenity/ui/dialogs/DirectoryChooserDialog.java deleted file mode 100644 index 116639183..000000000 --- a/serenity-app/src/main/java/us/nineworlds/serenity/ui/dialogs/DirectoryChooserDialog.java +++ /dev/null @@ -1,274 +0,0 @@ -package us.nineworlds.serenity.ui.dialogs; - -import android.app.AlertDialog; -import android.content.Context; -import android.content.DialogInterface; -import android.content.DialogInterface.OnClickListener; -import android.content.DialogInterface.OnKeyListener; -import android.graphics.Color; -import android.os.Environment; -import android.text.Editable; -import android.view.Gravity; -import android.view.KeyEvent; -import android.view.View; -import android.view.ViewGroup; -import android.view.ViewGroup.LayoutParams; -import android.widget.ArrayAdapter; -import android.widget.Button; -import android.widget.EditText; -import android.widget.LinearLayout; -import android.widget.TextView; -import android.widget.Toast; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -import us.nineworlds.serenity.R; - -public class DirectoryChooserDialog { - private boolean m_isNewFolderEnabled = true; - private String m_sdcardDirectory = ""; - private Context m_context; - private TextView m_titleView; - - private String m_dir = ""; - private List m_subdirs = null; - private ChosenDirectoryListener m_chosenDirectoryListener = null; - private ArrayAdapter m_listAdapter = null; - - public interface ChosenDirectoryListener { - public void onChosenDir(String chosenDir); - } - - public DirectoryChooserDialog(Context context, ChosenDirectoryListener chosenDirectoryListener) { - m_context = context; - m_sdcardDirectory = Environment.getExternalStorageDirectory().getAbsolutePath(); - m_chosenDirectoryListener = chosenDirectoryListener; - - try { - m_sdcardDirectory = new File(m_sdcardDirectory).getCanonicalPath(); - } catch (IOException ioe) { - } - } - - public void setNewFolderEnabled(boolean isNewFolderEnabled) { - m_isNewFolderEnabled = isNewFolderEnabled; - } - - public boolean getNewFolderEnabled() { - return m_isNewFolderEnabled; - } - - // ///////////////////////////////////////////////////////////////////// - // chooseDirectory() - load directory chooser dialog for initial - // default sdcard directory - // ///////////////////////////////////////////////////////////////////// - - public void chooseDirectory() { - // Initial directory is sdcard directory - chooseDirectory(m_sdcardDirectory); - } - - // ////////////////////////////////////////////////////////////////////////////// - // chooseDirectory(String dir) - load directory chooser dialog for initial - // input 'dir' directory - // ////////////////////////////////////////////////////////////////////////////// - - public void chooseDirectory(String dir) { - File dirFile = new File(dir); - if (!dirFile.exists() || !dirFile.isDirectory()) { - dir = m_sdcardDirectory; - } - - try { - dir = new File(dir).getCanonicalPath(); - } catch (IOException ioe) { - return; - } - - m_dir = dir; - m_subdirs = getDirectories(dir); - - class DirectoryOnClickListener implements DialogInterface.OnClickListener { - @Override public void onClick(DialogInterface dialog, int item) { - // Navigate into the sub-directory - m_dir += "/" + ((AlertDialog) dialog).getListView().getAdapter().getItem(item); - updateDirectory(); - } - } - - AlertDialog.Builder dialogBuilder = - createDirectoryChooserDialog(dir, m_subdirs, new DirectoryOnClickListener()); - - dialogBuilder.setPositiveButton(R.string.button_ok, new OnClickListener() { - - @Override public void onClick(DialogInterface dialog, int which) { - // Current directory chosen - if (m_chosenDirectoryListener != null) { - // Call registered listener supplied with the chosen - // directory - m_chosenDirectoryListener.onChosenDir(m_dir); - } - } - }).setNegativeButton(R.string.cancel, null); - - final AlertDialog dirsDialog = dialogBuilder.create(); - - dirsDialog.setOnKeyListener(new OnKeyListener() { - @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { - // Back button pressed - if (m_dir.equals(m_sdcardDirectory)) { - // The very top level directory, do nothing - return false; - } else { - // Navigate back to an upper directory - m_dir = new File(m_dir).getParent(); - updateDirectory(); - } - - return true; - } else { - return false; - } - } - }); - - // Show directory chooser dialog - dirsDialog.show(); - } - - private boolean createSubDir(String newDir) { - File newDirFile = new File(newDir); - if (!newDirFile.exists()) { - return newDirFile.mkdir(); - } - - return false; - } - - private List getDirectories(String dir) { - List dirs = new ArrayList(); - - try { - File dirFile = new File(dir); - if (!dirFile.exists() || !dirFile.isDirectory()) { - return dirs; - } - - for (File file : dirFile.listFiles()) { - if (file.isDirectory()) { - dirs.add(file.getName()); - } - } - } catch (Exception e) { - } - - Collections.sort(dirs, new Comparator() { - @Override public int compare(String o1, String o2) { - return o1.compareTo(o2); - } - }); - - return dirs; - } - - private AlertDialog.Builder createDirectoryChooserDialog(String title, List listItems, - DialogInterface.OnClickListener onClickListener) { - AlertDialog.Builder dialogBuilder = - new AlertDialog.Builder(m_context, android.R.style.Theme_Holo_Dialog); - - // Create custom view for AlertDialog title containing - // current directory TextView and possible 'New folder' button. - // Current directory TextView allows long directory path to be wrapped - // to multiple lines. - LinearLayout titleLayout = new LinearLayout(m_context); - titleLayout.setOrientation(LinearLayout.VERTICAL); - - m_titleView = new TextView(m_context); - m_titleView.setLayoutParams( - new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); - m_titleView.setTextAppearance(m_context, android.R.style.TextAppearance_Large); - m_titleView.setTextColor(m_context.getResources().getColor(android.R.color.white)); - m_titleView.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL); - m_titleView.setText(title); - - Button newDirButton = new Button(m_context); - newDirButton.setLayoutParams( - new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); - newDirButton.setText(R.string.new_folder); - newDirButton.setOnClickListener(new View.OnClickListener() { - - @Override public void onClick(View v) { - final EditText input = new EditText(m_context); - - // Show new folder name input dialog - new AlertDialog.Builder(m_context).setTitle(R.string.new_folder_name) - .setView(input) - .setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() { - @Override public void onClick(DialogInterface dialog, int whichButton) { - Editable newDir = input.getText(); - String newDirName = newDir.toString(); - // Create new directory - if (createSubDir(m_dir + "/" + newDirName)) { - // Navigate into the new directory - m_dir += "/" + newDirName; - updateDirectory(); - } else { - Toast.makeText(m_context, "Failed to create '" + newDirName + "' folder", - Toast.LENGTH_SHORT).show(); - } - } - }) - .setNegativeButton(R.string.cancel, null) - .show(); - } - }); - - if (!m_isNewFolderEnabled) { - newDirButton.setVisibility(View.GONE); - } - - titleLayout.addView(m_titleView); - titleLayout.addView(newDirButton); - - dialogBuilder.setCustomTitle(titleLayout); - - m_listAdapter = createListAdapter(listItems); - - dialogBuilder.setSingleChoiceItems(m_listAdapter, -1, onClickListener); - dialogBuilder.setCancelable(false); - - return dialogBuilder; - } - - private void updateDirectory() { - m_subdirs.clear(); - m_subdirs.addAll(getDirectories(m_dir)); - m_titleView.setText(m_dir); - - m_listAdapter.notifyDataSetChanged(); - } - - private ArrayAdapter createListAdapter(List items) { - return new ArrayAdapter(m_context, android.R.layout.select_dialog_item, - android.R.id.text1, items) { - @Override public View getView(int position, View convertView, ViewGroup parent) { - View v = super.getView(position, convertView, parent); - - if (v instanceof TextView) { - // Enable list item (directory) text wrapping - TextView tv = (TextView) v; - tv.getLayoutParams().height = LayoutParams.WRAP_CONTENT; - tv.setTextColor(Color.WHITE); - tv.setEllipsize(null); - } - return v; - } - }; - } -} \ No newline at end of file diff --git a/serenity-app/src/main/kotlin/us/nineworlds/serenity/core/util/StringPreference.kt b/serenity-app/src/main/kotlin/us/nineworlds/serenity/core/util/StringPreference.kt index 0fb66a063..88addb260 100644 --- a/serenity-app/src/main/kotlin/us/nineworlds/serenity/core/util/StringPreference.kt +++ b/serenity-app/src/main/kotlin/us/nineworlds/serenity/core/util/StringPreference.kt @@ -5,20 +5,20 @@ import androidx.annotation.NonNull import androidx.annotation.Nullable class StringPreference( - @NonNull private val preferences: SharedPreferences, - @NonNull private val key: String, - @Nullable private val defaultValue: String + private val preferences: SharedPreferences, + private val key: String, + private val defaultValue: String? ) { val isSet: Boolean get() = preferences.contains(key) - @Nullable - fun get(): String { - return preferences.getString(key, defaultValue)!! + + fun get(): String? { + return preferences.getString(key, defaultValue) } - fun set(@Nullable value: String) { + fun set(value: String) { preferences.edit().putString(key, value).commit() }