mirror of
https://github.com/nextcloud/android.git
synced 2024-11-28 10:18:59 +03:00
Convert to kt
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
3363a1496d
commit
4dbae505ff
1 changed files with 71 additions and 84 deletions
|
@ -1,105 +1,92 @@
|
||||||
/**
|
/**
|
||||||
* ownCloud Android client application
|
* ownCloud Android client application
|
||||||
*
|
*
|
||||||
* Copyright (C) 2015 ownCloud Inc.
|
* Copyright (C) 2015 ownCloud Inc.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License version 2,
|
* it under the terms of the GNU General Public License version 2,
|
||||||
* as published by the Free Software Foundation.
|
* as published by the Free Software Foundation.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http:></http:>//www.gnu.org/licenses/>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.owncloud.android.ui.dialog;
|
@file:Suppress("DEPRECATION")
|
||||||
|
|
||||||
import android.app.Dialog;
|
package com.owncloud.android.ui.dialog
|
||||||
import android.app.ProgressDialog;
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.DialogInterface.OnKeyListener;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.view.KeyEvent;
|
|
||||||
import android.widget.ProgressBar;
|
|
||||||
|
|
||||||
import com.nextcloud.client.di.Injectable;
|
import android.app.Dialog
|
||||||
import com.owncloud.android.R;
|
import android.app.ProgressDialog
|
||||||
import com.owncloud.android.utils.theme.ViewThemeUtils;
|
import android.content.DialogInterface
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.KeyEvent
|
||||||
|
import android.widget.ProgressBar
|
||||||
|
import androidx.fragment.app.DialogFragment
|
||||||
|
import com.nextcloud.client.di.Injectable
|
||||||
|
import com.owncloud.android.R
|
||||||
|
import com.owncloud.android.utils.theme.ViewThemeUtils
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
import javax.inject.Inject;
|
class IndeterminateProgressDialog : DialogFragment(), Injectable {
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.fragment.app.DialogFragment;
|
|
||||||
|
|
||||||
|
|
||||||
public class IndeterminateProgressDialog extends DialogFragment implements Injectable {
|
|
||||||
|
|
||||||
private static final String ARG_MESSAGE_ID = IndeterminateProgressDialog.class.getCanonicalName() + ".ARG_MESSAGE_ID";
|
|
||||||
private static final String ARG_CANCELABLE = IndeterminateProgressDialog.class.getCanonicalName() + ".ARG_CANCELABLE";
|
|
||||||
|
|
||||||
@Inject ViewThemeUtils viewThemeUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Public factory method to get dialog instances.
|
|
||||||
*
|
|
||||||
* @param messageId Resource id for a message to show in the dialog.
|
|
||||||
* @param cancelable If 'true', the dialog can be cancelled by the user input (BACK button, touch outside...)
|
|
||||||
* @return New dialog instance, ready to show.
|
|
||||||
*/
|
|
||||||
public static IndeterminateProgressDialog newInstance(int messageId, boolean cancelable) {
|
|
||||||
IndeterminateProgressDialog fragment = new IndeterminateProgressDialog();
|
|
||||||
fragment.setStyle(DialogFragment.STYLE_NO_FRAME, R.style.ownCloud_AlertDialog);
|
|
||||||
Bundle args = new Bundle();
|
|
||||||
args.putInt(ARG_MESSAGE_ID, messageId);
|
|
||||||
args.putBoolean(ARG_CANCELABLE, cancelable);
|
|
||||||
fragment.setArguments(args);
|
|
||||||
return fragment;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@JvmField
|
||||||
|
@Inject
|
||||||
|
var viewThemeUtils: ViewThemeUtils? = null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@NonNull
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
@Override
|
// / create indeterminate progress dialog
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
val progressDialog = ProgressDialog(requireActivity(), R.style.ProgressDialogTheme)
|
||||||
/// create indeterminate progress dialog
|
progressDialog.isIndeterminate = true
|
||||||
final ProgressDialog progressDialog = new ProgressDialog(getActivity(), R.style.ProgressDialogTheme);
|
progressDialog.setOnShowListener {
|
||||||
progressDialog.setIndeterminate(true);
|
val v = progressDialog.findViewById<ProgressBar>(android.R.id.progress)
|
||||||
progressDialog.setOnShowListener(dialog -> {
|
viewThemeUtils?.platform?.tintDrawable(requireContext(), v.indeterminateDrawable)
|
||||||
ProgressBar v = progressDialog.findViewById(android.R.id.progress);
|
|
||||||
viewThemeUtils.platform.tintDrawable(requireContext(), v.getIndeterminateDrawable());
|
|
||||||
});
|
|
||||||
|
|
||||||
/// set message
|
|
||||||
int messageId = getArguments().getInt(ARG_MESSAGE_ID, R.string.placeholder_sentence);
|
|
||||||
progressDialog.setMessage(getString(messageId));
|
|
||||||
|
|
||||||
/// set cancellation behavior
|
|
||||||
boolean cancelable = getArguments().getBoolean(ARG_CANCELABLE, false);
|
|
||||||
if (!cancelable) {
|
|
||||||
progressDialog.setCancelable(false);
|
|
||||||
// disable the back button
|
|
||||||
OnKeyListener keyListener = new OnKeyListener() {
|
|
||||||
@Override
|
|
||||||
public boolean onKey(DialogInterface dialog, int keyCode,
|
|
||||||
KeyEvent event) {
|
|
||||||
|
|
||||||
return keyCode == KeyEvent.KEYCODE_BACK;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
progressDialog.setOnKeyListener(keyListener);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return progressDialog;
|
// / set message
|
||||||
|
val messageId = requireArguments().getInt(ARG_MESSAGE_ID, R.string.placeholder_sentence)
|
||||||
|
progressDialog.setMessage(getString(messageId))
|
||||||
|
|
||||||
|
// / set cancellation behavior
|
||||||
|
val cancelable = requireArguments().getBoolean(ARG_CANCELABLE, false)
|
||||||
|
if (!cancelable) {
|
||||||
|
progressDialog.setCancelable(false)
|
||||||
|
// disable the back button
|
||||||
|
val keyListener =
|
||||||
|
DialogInterface.OnKeyListener { _, keyCode, _ -> keyCode == KeyEvent.KEYCODE_BACK }
|
||||||
|
progressDialog.setOnKeyListener(keyListener)
|
||||||
|
}
|
||||||
|
return progressDialog
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val ARG_MESSAGE_ID = IndeterminateProgressDialog::class.java.canonicalName?.plus(".ARG_MESSAGE_ID")
|
||||||
|
private val ARG_CANCELABLE = IndeterminateProgressDialog::class.java.canonicalName?.plus(".ARG_CANCELABLE")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public factory method to get dialog instances.
|
||||||
|
*
|
||||||
|
* @param messageId Resource id for a message to show in the dialog.
|
||||||
|
* @param cancelable If 'true', the dialog can be cancelled by the user input (BACK button, touch outside...)
|
||||||
|
* @return New dialog instance, ready to show.
|
||||||
|
*/
|
||||||
|
@JvmStatic
|
||||||
|
fun newInstance(messageId: Int, cancelable: Boolean): IndeterminateProgressDialog {
|
||||||
|
val fragment = IndeterminateProgressDialog()
|
||||||
|
fragment.setStyle(STYLE_NO_FRAME, R.style.ownCloud_AlertDialog)
|
||||||
|
val args = Bundle()
|
||||||
|
args.putInt(ARG_MESSAGE_ID, messageId)
|
||||||
|
args.putBoolean(ARG_CANCELABLE, cancelable)
|
||||||
|
fragment.arguments = args
|
||||||
|
return fragment
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue