diff --git a/app/build.gradle b/app/build.gradle index 15eae175..e15b3b8d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -44,6 +44,10 @@ android { exclude 'META-INF/notice.txt' exclude 'META-INF/ASL2.0' } + compileOptions { + sourceCompatibility = '1.8' + targetCompatibility = '1.8' + } } androidExtensions { diff --git a/app/src/main/java/com/stevenschoen/putionew/ButtonBarLayout.kt b/app/src/main/java/com/stevenschoen/putionew/ButtonBarLayout.kt new file mode 100644 index 00000000..0532962f --- /dev/null +++ b/app/src/main/java/com/stevenschoen/putionew/ButtonBarLayout.kt @@ -0,0 +1,38 @@ +package com.stevenschoen.putionew + +import android.content.Context +import android.graphics.drawable.Drawable +import android.graphics.drawable.GradientDrawable +import android.util.AttributeSet +import android.view.Gravity +import android.widget.LinearLayout +import androidx.core.content.res.getDimensionPixelSizeOrThrow +import androidx.core.content.res.use + +class ButtonBarLayout @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = R.attr.buttonBarLayoutStyle, + defStyleRes: Int = R.style.Widget_Putio_ButtonBarLayout +) : LinearLayout(context, attrs, defStyleAttr, defStyleRes) { + + private var buttonPadding: Int = 0 + + init { + orientation = HORIZONTAL + gravity = Gravity.END + + context.obtainStyledAttributes(attrs, R.styleable.ButtonBarLayout, defStyleAttr, defStyleRes) + .use { attrsArray -> + buttonPadding = attrsArray.getDimensionPixelSizeOrThrow( + R.styleable.ButtonBarLayout_buttonPadding + ) + } + + dividerDrawable = GradientDrawable().apply { + setSize(buttonPadding, 0) + } + showDividers = SHOW_DIVIDER_MIDDLE + } + +} diff --git a/app/src/main/java/com/stevenschoen/putionew/PutioUtils.java b/app/src/main/java/com/stevenschoen/putionew/PutioUtils.java index fc267da3..33b0bb5a 100644 --- a/app/src/main/java/com/stevenschoen/putionew/PutioUtils.java +++ b/app/src/main/java/com/stevenschoen/putionew/PutioUtils.java @@ -5,15 +5,11 @@ import android.content.ActivityNotFoundException; import android.content.ClipData; import android.content.Context; -import android.content.DialogInterface; -import android.content.DialogInterface.OnCancelListener; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Resources; import android.database.Cursor; import android.graphics.Bitmap; -import android.net.ConnectivityManager; -import android.net.NetworkInfo; import android.net.Uri; import android.os.AsyncTask; import android.preference.PreferenceManager; @@ -24,9 +20,6 @@ import android.renderscript.ScriptIntrinsicBlur; import android.text.format.DateFormat; import android.view.View; -import android.view.View.OnClickListener; -import android.webkit.MimeTypeMap; -import android.widget.Button; import android.widget.Toast; import com.google.android.material.dialog.MaterialAlertDialogBuilder; @@ -35,7 +28,6 @@ import com.google.gson.GsonBuilder; import com.squareup.picasso.Transformation; import com.stevenschoen.putionew.model.PutioRestInterface; -import com.stevenschoen.putionew.model.ResponseOrError; import com.stevenschoen.putionew.model.files.PutioFile; import com.stevenschoen.putionew.model.files.PutioSubtitle; @@ -47,9 +39,6 @@ import java.util.List; import java.util.Locale; -import io.reactivex.Single; -import io.reactivex.SingleObserver; -import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.schedulers.Schedulers; import okhttp3.Interceptor; import okhttp3.OkHttpClient; @@ -82,13 +71,6 @@ public PutioUtils(Context context) throws NoTokenException { this.putioRestInterface = makePutioRestInterface(baseUrl).create(PutioRestInterface.class); } - public static Dialog showPutioDialog(Context context, String title, int contentViewId) { - return new MaterialAlertDialogBuilder(context) - .setTitle(title) - .setView(contentViewId) - .show(); - } - public static String getNameFromUri(Context context, Uri uri) { if (uri.getScheme().equals("file")) { return new File(uri.getPath()).getName(); @@ -126,18 +108,6 @@ public static String resolveRedirect(String url) throws IOException { return url; } - private static void open(Uri uri, Context context) { - String typename = MimeTypeMap.getFileExtensionFromUrl(uri.toString()); - String type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(typename); - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setDataAndType(uri, type); - try { - context.startActivity(intent); - } catch (ActivityNotFoundException e) { - Toast.makeText(context, context.getString(R.string.cantopenbecausetype), Toast.LENGTH_LONG).show(); - } - } - public static String humanReadableByteCount(long bytes, boolean si) { int unit = si ? 1000 : 1024; if (bytes < unit) @@ -278,17 +248,11 @@ class GetStreamUrlAndPlay extends AsyncTask GetStreamUrlAndPlay.this.cancel(true)) + .show(); } @Override @@ -311,7 +275,7 @@ protected GetStreamUrlAndPlayResult doInBackground(String... params) { // No subtitles, not a problem } else { e.printStackTrace(); - if (context != null && context instanceof Activity) { + if (context instanceof Activity) { ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { @@ -350,46 +314,6 @@ public void onPostExecute(GetStreamUrlAndPlayResult result) { new GetStreamUrlAndPlay().execute(url); } - public Dialog removeTransferDialog( - final Context context, final SingleObserver observer, - final long... idsToDelete) { - final Dialog removeDialog = showPutioDialog(context, context.getString(R.string.removetransfertitle), R.layout.dialog_removetransfer); - - Button removeRemove = removeDialog.findViewById(R.id.button_removetransfer_remove); - removeRemove.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - Single cancelObservable = getRestInterface() - .cancelTransfer(PutioUtils.longsToString(idsToDelete)) - .observeOn(AndroidSchedulers.mainThread()); - if (observer != null) { - cancelObservable.subscribe(observer); - } else { - cancelObservable.subscribe(); - } - Toast.makeText(context, context.getString(R.string.transferremoved), Toast.LENGTH_SHORT).show(); - removeDialog.dismiss(); - } - }); - - Button cancelRemove = removeDialog.findViewById(R.id.button_removetransfer_cancel); - cancelRemove.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - removeDialog.cancel(); - } - }); - - return removeDialog; - } - - public boolean isConnected(Context context) { - ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - - NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); - return activeNetwork != null && activeNetwork.isConnected(); - } - private static class GetStreamUrlAndPlayResult { String url; List subtitles; diff --git a/app/src/main/java/com/stevenschoen/putionew/transfers/TransfersFragment.kt b/app/src/main/java/com/stevenschoen/putionew/transfers/TransfersFragment.kt index 7206c859..442705c2 100644 --- a/app/src/main/java/com/stevenschoen/putionew/transfers/TransfersFragment.kt +++ b/app/src/main/java/com/stevenschoen/putionew/transfers/TransfersFragment.kt @@ -17,6 +17,7 @@ import android.widget.Toast import androidx.fragment.app.Fragment import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView +import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.stevenschoen.putionew.PutioApplication import com.stevenschoen.putionew.PutioTransfersService import com.stevenschoen.putionew.PutioTransfersService.TransfersServiceBinder @@ -72,7 +73,7 @@ class TransfersFragment : RxFragment() { transfersListView = view.findViewById(R.id.transferslist) transfersListView!!.layoutManager = LinearLayoutManager( - context, LinearLayoutManager.VERTICAL, false + context, RecyclerView.VERTICAL, false ) val padding = resources.getDimensionPixelSize(R.dimen.transfers_card_padding) transfersListView!!.addItemDecoration(object : RecyclerView.ItemDecoration() { @@ -209,7 +210,18 @@ class TransfersFragment : RxFragment() { .observeOn(AndroidSchedulers.mainThread()) .subscribe(makeUpdateNowObserver()) } else { - utils!!.removeTransferDialog(activity, makeUpdateNowObserver(), transfer.id).show() + MaterialAlertDialogBuilder(context, R.style.ThemeOverlay_Putio_Dialog_Alert_Destructive) + .setTitle(R.string.removetransfertitle) + .setMessage(R.string.removetransferbody) + .setPositiveButton(R.string.remove) { _, _ -> + utils!!.restInterface.cancelTransfer(transfer.id.toString()) + .bindToLifecycle(this) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(makeUpdateNowObserver()) + Toast.makeText(context, R.string.transferremoved, Toast.LENGTH_SHORT).show() + } + .setNegativeButton(R.string.cancel, null) + .show() } hideOptionsIfShowing() } diff --git a/app/src/main/res/layout/addtransfer_file.xml b/app/src/main/res/layout/addtransfer_file.xml index e55c4361..41d387c0 100644 --- a/app/src/main/res/layout/addtransfer_file.xml +++ b/app/src/main/res/layout/addtransfer_file.xml @@ -65,15 +65,10 @@ android:layout_marginEnd="16dp" /> -