diff --git a/catroid/src/main/java/org/catrobat/catroid/ui/MainMenuActivity.java b/catroid/src/main/java/org/catrobat/catroid/ui/MainMenuActivity.java deleted file mode 100644 index bf42e552a0e..00000000000 --- a/catroid/src/main/java/org/catrobat/catroid/ui/MainMenuActivity.java +++ /dev/null @@ -1,351 +0,0 @@ -/* - * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2021 The Catrobat Team - * () - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * An additional term exception under section 7 of the GNU Affero - * General Public License, version 3, is available at - * http://developer.catrobat.org/license_additional_term - * - * This program 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.catrobat.catroid.ui; - -import android.content.ActivityNotFoundException; -import android.content.Intent; -import android.net.Uri; -import android.os.Bundle; -import android.preference.PreferenceManager; -import android.text.Html; -import android.text.Spannable; -import android.text.SpannableString; -import android.text.method.LinkMovementMethod; -import android.text.style.ForegroundColorSpan; -import android.util.Log; -import android.view.KeyEvent; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.widget.TextView; - -import org.catrobat.catroid.BuildConfig; -import org.catrobat.catroid.ProjectManager; -import org.catrobat.catroid.R; -import org.catrobat.catroid.cast.CastManager; -import org.catrobat.catroid.common.Constants; -import org.catrobat.catroid.common.Survey; -import org.catrobat.catroid.content.Project; -import org.catrobat.catroid.io.ZipArchiver; -import org.catrobat.catroid.io.asynctask.ProjectLoadTask; -import org.catrobat.catroid.io.asynctask.ProjectSaver; -import org.catrobat.catroid.stage.StageActivity; -import org.catrobat.catroid.ui.dialogs.TermsOfUseDialogFragment; -import org.catrobat.catroid.ui.recyclerview.dialog.AboutDialogFragment; -import org.catrobat.catroid.ui.recyclerview.fragment.MainMenuFragment; -import org.catrobat.catroid.ui.settingsfragments.SettingsFragment; -import org.catrobat.catroid.utils.FileMetaDataExtractor; -import org.catrobat.catroid.utils.ScreenValueHandler; -import org.catrobat.catroid.utils.ToastUtil; -import org.catrobat.catroid.utils.Utils; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; - -import androidx.appcompat.app.AlertDialog; -import kotlin.Lazy; - -import static org.catrobat.catroid.common.FlavoredConstants.CATROBAT_HELP_URL; -import static org.catrobat.catroid.common.FlavoredConstants.DEFAULT_ROOT_DIRECTORY; -import static org.catrobat.catroid.common.FlavoredConstants.PRIVACY_POLICY_URL; -import static org.catrobat.catroid.common.SharedPreferenceKeys.AGREED_TO_PRIVACY_POLICY_VERSION; -import static org.koin.java.KoinJavaComponent.inject; - -public class MainMenuActivity extends BaseCastActivity implements - ProjectLoadTask.ProjectLoadListener { - - private final Lazy projectManager = inject(ProjectManager.class); - - public static final String TAG = MainMenuActivity.class.getSimpleName(); - - private int oldPrivacyPolicy = 0; - - public static Survey surveyCampaign; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - SettingsFragment.setToChosenLanguage(this); - - PreferenceManager.setDefaultValues(this, R.xml.preferences, true); - ScreenValueHandler.updateScreenWidthAndHeight(this); - - oldPrivacyPolicy = PreferenceManager.getDefaultSharedPreferences(this) - .getInt(AGREED_TO_PRIVACY_POLICY_VERSION, 0); - - loadContent(); - - if (oldPrivacyPolicy != Constants.CATROBAT_TERMS_OF_USE_ACCEPTED) { - showTermsOfUseDialog(); - } - - surveyCampaign = new Survey(this); - surveyCampaign.showSurvey(this); - } - - private void showTermsOfUseDialog() { - View view = View.inflate(this, R.layout.privacy_policy_view, null); - - TextView termsOfUseUrlTextView = view.findViewById(R.id.dialog_privacy_policy_text_view_url); - - termsOfUseUrlTextView.setMovementMethod(LinkMovementMethod.getInstance()); - - String termsOfUseUrlStringText = getString(R.string.main_menu_terms_of_use); - - String termsOfUseUrl = getString(R.string.terms_of_use_link_template, Constants.CATROBAT_TERMS_OF_USE_URL - + Constants.CATROBAT_TERMS_OF_USE_TOKEN_FLAVOR_URL + BuildConfig.FLAVOR - + Constants.CATROBAT_TERMS_OF_USE_TOKEN_VERSION_URL + BuildConfig.VERSION_CODE, - termsOfUseUrlStringText); - - termsOfUseUrlTextView.setText(Html.fromHtml(termsOfUseUrl)); - - new AlertDialog.Builder(this) - .setNegativeButton(R.string.decline, (dialog, which) -> { - handleDeclinedPrivacyPolicyButton(); - }) - .setPositiveButton(R.string.accept, (dialog, which) -> { - handleAgreedToPrivacyPolicyButton(); - }) - .setCancelable(false) - .setOnKeyListener((dialog, keyCode, event) -> { - if (keyCode == KeyEvent.KEYCODE_BACK) { - finish(); - return true; - } - return false; - }) - .setView(view) - .show(); - } - - public void handleAgreedToPrivacyPolicyButton() { - PreferenceManager.getDefaultSharedPreferences(this) - .edit() - .putInt(AGREED_TO_PRIVACY_POLICY_VERSION, Constants.CATROBAT_TERMS_OF_USE_ACCEPTED) - .apply(); - - if (BuildConfig.FEATURE_APK_GENERATOR_ENABLED) { - prepareStandaloneProject(); - } - } - - public void handleDeclinedPrivacyPolicyButton() { - View dialogView = View.inflate(this, - R.layout.declined_terms_of_use_and_service_alert_view, null); - - String linkString = getString(R.string.about_link_template, - Constants.BASE_APP_URL_HTTPS, - getString(R.string.share_website_text)); - - TextView linkTextView = dialogView.findViewById(R.id.share_website_view); - linkTextView.setMovementMethod(LinkMovementMethod.getInstance()); - linkTextView.setText(Html.fromHtml(linkString)); - - new AlertDialog.Builder(this) - .setView(dialogView) - .setPositiveButton(R.string.ok, (dialog, which) -> { - showTermsOfUseDialog(); - }) - .setCancelable(false) - .setOnKeyListener((dialog, keyCode, event) -> { - if (keyCode == KeyEvent.KEYCODE_BACK) { - dialog.cancel(); - showTermsOfUseDialog(); - return true; - } - return false; - }) - .show(); - } - - private void loadContent() { - if (BuildConfig.FEATURE_APK_GENERATOR_ENABLED) { - setContentView(R.layout.activity_main_menu_splashscreen); - if (oldPrivacyPolicy == Constants.CATROBAT_TERMS_OF_USE_ACCEPTED) { - prepareStandaloneProject(); - } - return; - } - - setContentView(R.layout.activity_main_menu); - setSupportActionBar(findViewById(R.id.toolbar)); - getSupportActionBar().setIcon(R.drawable.pc_toolbar_icon); - getSupportActionBar().setTitle(R.string.app_name); - - setShowProgressBar(true); - - if (SettingsFragment.isCastSharedPreferenceEnabled(this)) { - CastManager.getInstance().initializeCast(this); - } - - loadFragment(); - } - - private void loadFragment() { - getSupportFragmentManager().beginTransaction() - .replace(R.id.fragment_container, new MainMenuFragment(), - MainMenuFragment.Companion.getTAG()) - .commit(); - setShowProgressBar(false); - - Intent intent = getIntent(); - if (intent != null - && intent.getAction() != null - && intent.getAction().equals("android.intent.action.VIEW") - && intent.getData() != null) { - Uri shareUri = intent.getData(); - - Intent webIntent = new Intent(this, WebViewActivity.class); - webIntent.putExtra(WebViewActivity.INTENT_PARAMETER_URL, shareUri.toString()); - startActivity(webIntent); - } - } - - private void setShowProgressBar(boolean show) { - findViewById(R.id.progress_bar).setVisibility(show ? View.VISIBLE : View.GONE); - findViewById(R.id.fragment_container).setVisibility(show ? View.GONE : View.VISIBLE); - } - - @Override - public void onPause() { - super.onPause(); - - Project currentProject = projectManager.getValue().getCurrentProject(); - - if (currentProject != null) { - new ProjectSaver(currentProject, getApplicationContext()).saveProjectAsync(); - - Utils.setLastUsedProjectName(getApplicationContext(), currentProject.getName()); - } - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.menu_main_menu, menu); - - String scratchConverter = getString(R.string.main_menu_scratch_converter); - SpannableString scratchConverterBeta = new SpannableString(scratchConverter - + " " - + getString(R.string.beta)); - scratchConverterBeta.setSpan( - new ForegroundColorSpan(getResources().getColor(R.color.beta_label_color)), - scratchConverter.length(), scratchConverterBeta.length(), - Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - menu.findItem(R.id.menu_scratch_converter).setTitle(scratchConverterBeta); - return true; - } - - @Override - public boolean onPrepareOptionsMenu(Menu menu) { - menu.findItem(R.id.menu_login).setVisible(!Utils.isUserLoggedIn(this)); - menu.findItem(R.id.menu_logout).setVisible(Utils.isUserLoggedIn(this)); - if (!BuildConfig.FEATURE_SCRATCH_CONVERTER_ENABLED) { - menu.removeItem(R.id.menu_scratch_converter); - } - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.menu_rate_app: - if (Utils.checkIsNetworkAvailableAndShowErrorMessage(this)) { - try { - startActivity(new Intent(Intent.ACTION_VIEW, - Uri.parse("market://details?id=" + getPackageName()))); - } catch (ActivityNotFoundException e) { - ToastUtil.showError(this, R.string.main_menu_play_store_not_installed); - } - } - break; - case R.id.menu_terms_of_use: - new TermsOfUseDialogFragment().show(getSupportFragmentManager(), TermsOfUseDialogFragment.TAG); - break; - case R.id.menu_privacy_policy: - Intent browserIntent = new Intent(Intent.ACTION_VIEW, - Uri.parse(PRIVACY_POLICY_URL)); - startActivity(browserIntent); - break; - case R.id.menu_about: - new AboutDialogFragment().show(getSupportFragmentManager(), AboutDialogFragment.TAG); - break; - case R.id.menu_scratch_converter: - if (Utils.checkIsNetworkAvailableAndShowErrorMessage(this)) { - startActivity(new Intent(this, ScratchConverterActivity.class)); - } - break; - case R.id.settings: - startActivity(new Intent(this, SettingsActivity.class)); - break; - case R.id.menu_login: - startActivity(new Intent(this, SignInActivity.class)); - break; - case R.id.menu_logout: - Utils.logoutUser(this); - ToastUtil.showSuccess(this, R.string.logout_successful); - break; - case R.id.menu_help: - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(CATROBAT_HELP_URL))); - break; - default: - return super.onOptionsItemSelected(item); - } - return true; - } - - private void prepareStandaloneProject() { - try { - InputStream inputStream = getAssets().open(BuildConfig.START_PROJECT + ".zip"); - File projectDir = new File(DEFAULT_ROOT_DIRECTORY, - FileMetaDataExtractor.encodeSpecialCharsForFileSystem(BuildConfig.PROJECT_NAME)); - new ZipArchiver() - .unzip(inputStream, projectDir); - new ProjectLoadTask(projectDir, this) - .setListener(this) - .execute(); - } catch (IOException e) { - Log.e("STANDALONE", "Cannot unpack standalone project: ", e); - } - } - - @Override - public void onLoadFinished(boolean success) { - if (BuildConfig.FEATURE_APK_GENERATOR_ENABLED && success) { - startActivityForResult( - new Intent(this, StageActivity.class), StageActivity.REQUEST_START_STAGE); - } - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - if (BuildConfig.FEATURE_APK_GENERATOR_ENABLED) { - if (requestCode == StageActivity.REQUEST_START_STAGE) { - finish(); - } - } else { - super.onActivityResult(requestCode, resultCode, data); - } - } -} diff --git a/catroid/src/main/java/org/catrobat/catroid/ui/MainMenuActivity.kt b/catroid/src/main/java/org/catrobat/catroid/ui/MainMenuActivity.kt new file mode 100644 index 00000000000..0054c4f7bed --- /dev/null +++ b/catroid/src/main/java/org/catrobat/catroid/ui/MainMenuActivity.kt @@ -0,0 +1,356 @@ +/* + * Catroid: An on-device visual programming system for Android devices + * Copyright (C) 2010-2021 The Catrobat Team + * () + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * An additional term exception under section 7 of the GNU Affero + * General Public License, version 3, is available at + * http://developer.catrobat.org/license_additional_term + * + * This program 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.catrobat.catroid.ui + +import android.content.ActivityNotFoundException +import android.content.DialogInterface +import android.content.Intent +import android.net.Uri +import android.os.Bundle +import android.preference.PreferenceManager +import android.text.Html +import android.text.Spannable +import android.text.SpannableString +import android.text.method.LinkMovementMethod +import android.text.style.ForegroundColorSpan +import android.util.Log +import android.view.KeyEvent +import android.view.Menu +import android.view.MenuItem +import android.view.View +import androidx.appcompat.app.AlertDialog +import org.catrobat.catroid.BuildConfig +import org.catrobat.catroid.ProjectManager +import org.catrobat.catroid.R +import org.catrobat.catroid.cast.CastManager +import org.catrobat.catroid.common.Constants +import org.catrobat.catroid.common.FlavoredConstants +import org.catrobat.catroid.common.FlavoredConstants.CATROBAT_HELP_URL +import org.catrobat.catroid.common.SharedPreferenceKeys +import org.catrobat.catroid.common.Survey +import org.catrobat.catroid.databinding.ActivityMainMenuBinding +import org.catrobat.catroid.databinding.ActivityMainMenuSplashscreenBinding +import org.catrobat.catroid.databinding.DeclinedTermsOfUseAndServiceAlertViewBinding +import org.catrobat.catroid.databinding.PrivacyPolicyViewBinding +import org.catrobat.catroid.databinding.ProgressBarBinding +import org.catrobat.catroid.io.ZipArchiver +import org.catrobat.catroid.io.asynctask.ProjectLoadTask +import org.catrobat.catroid.io.asynctask.ProjectLoadTask.ProjectLoadListener +import org.catrobat.catroid.io.asynctask.ProjectSaver +import org.catrobat.catroid.stage.StageActivity +import org.catrobat.catroid.ui.dialogs.TermsOfUseDialogFragment +import org.catrobat.catroid.ui.recyclerview.dialog.AboutDialogFragment +import org.catrobat.catroid.ui.recyclerview.fragment.MainMenuFragment +import org.catrobat.catroid.ui.settingsfragments.SettingsFragment +import org.catrobat.catroid.utils.FileMetaDataExtractor +import org.catrobat.catroid.utils.ScreenValueHandler +import org.catrobat.catroid.utils.ToastUtil +import org.catrobat.catroid.utils.Utils +import org.koin.android.ext.android.inject +import java.io.File +import java.io.IOException + +class MainMenuActivity : BaseCastActivity(), ProjectLoadListener { + + private lateinit var privacyPolicyBinding: PrivacyPolicyViewBinding + private lateinit var declinedTermsOfUseViewBinding: DeclinedTermsOfUseAndServiceAlertViewBinding + private lateinit var mainMenuBinding: ActivityMainMenuBinding + private val projectManager: ProjectManager by inject() + private var oldPrivacyPolicy = 0 + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + SettingsFragment.setToChosenLanguage(this) + + PreferenceManager.setDefaultValues(this, R.xml.preferences, true) + ScreenValueHandler.updateScreenWidthAndHeight(this) + + oldPrivacyPolicy = PreferenceManager.getDefaultSharedPreferences(this) + .getInt(SharedPreferenceKeys.AGREED_TO_PRIVACY_POLICY_VERSION, 0) + + loadContent() + + if (oldPrivacyPolicy != Constants.CATROBAT_TERMS_OF_USE_ACCEPTED) { + showTermsOfUseDialog() + } + + surveyCampaign = Survey(this) + surveyCampaign?.showSurvey(this) + } + + private fun showTermsOfUseDialog() { + privacyPolicyBinding = PrivacyPolicyViewBinding.inflate(layoutInflater) + val view = privacyPolicyBinding.root + val termsOfUseUrlTextView = privacyPolicyBinding.dialogPrivacyPolicyTextViewUrl + + termsOfUseUrlTextView.movementMethod = LinkMovementMethod.getInstance() + + val termsOfUseUrlStringText = getString(R.string.main_menu_terms_of_use) + val termsOfUseUrl = getString( + R.string.terms_of_use_link_template, + Constants.CATROBAT_TERMS_OF_USE_URL + + Constants.CATROBAT_TERMS_OF_USE_TOKEN_FLAVOR_URL + BuildConfig.FLAVOR + + Constants.CATROBAT_TERMS_OF_USE_TOKEN_VERSION_URL + BuildConfig.VERSION_CODE, + termsOfUseUrlStringText + ) + + termsOfUseUrlTextView.text = Html.fromHtml(termsOfUseUrl) + + AlertDialog.Builder(this) + .setNegativeButton(R.string.decline) { dialog: DialogInterface?, which: Int -> handleDeclinedPrivacyPolicyButton() } + .setPositiveButton(R.string.accept) { dialog: DialogInterface?, which: Int -> handleAgreedToPrivacyPolicyButton() } + .setCancelable(false) + .setOnKeyListener { dialog: DialogInterface?, keyCode: Int, event: KeyEvent? -> + if (keyCode == KeyEvent.KEYCODE_BACK) { + finish() + return@setOnKeyListener true + } + false + } + .setView(view) + .show() + } + + fun handleAgreedToPrivacyPolicyButton() { + PreferenceManager.getDefaultSharedPreferences(this) + .edit() + .putInt( + SharedPreferenceKeys.AGREED_TO_PRIVACY_POLICY_VERSION, + Constants.CATROBAT_TERMS_OF_USE_ACCEPTED + ) + .apply() + if (BuildConfig.FEATURE_APK_GENERATOR_ENABLED) { + prepareStandaloneProject() + } + } + + fun handleDeclinedPrivacyPolicyButton() { + declinedTermsOfUseViewBinding = + DeclinedTermsOfUseAndServiceAlertViewBinding.inflate(layoutInflater) + val dialogView = declinedTermsOfUseViewBinding.root + + val linkString = getString( + R.string.about_link_template, + Constants.BASE_APP_URL_HTTPS, + getString(R.string.share_website_text) + ) + + val linkTextView = declinedTermsOfUseViewBinding.shareWebsiteView + linkTextView.movementMethod = LinkMovementMethod.getInstance() + linkTextView.text = Html.fromHtml(linkString) + + AlertDialog.Builder(this) + .setView(dialogView) + .setPositiveButton(R.string.ok) { dialog: DialogInterface?, which: Int -> showTermsOfUseDialog() } + .setCancelable(false) + .setOnKeyListener { dialog: DialogInterface, keyCode: Int, event: KeyEvent? -> + if (keyCode == KeyEvent.KEYCODE_BACK) { + dialog.cancel() + showTermsOfUseDialog() + return@setOnKeyListener true + } + false + } + .show() + } + + private fun loadContent() { + if (BuildConfig.FEATURE_APK_GENERATOR_ENABLED) { + val mainMenuSplashscreenBinding = + ActivityMainMenuSplashscreenBinding.inflate(layoutInflater) + setContentView(mainMenuSplashscreenBinding.root) + if (oldPrivacyPolicy == Constants.CATROBAT_TERMS_OF_USE_ACCEPTED) { + prepareStandaloneProject() + } + return + } + mainMenuBinding = ActivityMainMenuBinding.inflate(layoutInflater) + setContentView(mainMenuBinding.root) + setSupportActionBar(findViewById(R.id.toolbar)) + supportActionBar?.setIcon(R.drawable.pc_toolbar_icon) + supportActionBar?.setTitle(R.string.app_name) + + setShowProgressBar(true) + + if (SettingsFragment.isCastSharedPreferenceEnabled(this)) { + CastManager.getInstance().initializeCast(this) + } + loadFragment() + } + + private fun loadFragment() { + supportFragmentManager.beginTransaction() + .replace( + mainMenuBinding.fragmentContainer.id, MainMenuFragment(), + MainMenuFragment.TAG + ) + .commit() + setShowProgressBar(false) + + val intent = intent + if (intent.action != null && intent.action == "android.intent.action.VIEW" && intent.data != null) { + val shareUri = intent.data + val webIntent = Intent(this, WebViewActivity::class.java) + webIntent.putExtra(WebViewActivity.INTENT_PARAMETER_URL, shareUri.toString()) + startActivity(webIntent) + } + } + + private fun setShowProgressBar(show: Boolean) { + val progressBarBinding = ProgressBarBinding.inflate(layoutInflater) + progressBarBinding.root.visibility = if (show) View.VISIBLE else View.GONE + mainMenuBinding.fragmentContainer.visibility = + if (show) View.GONE else View.VISIBLE + } + + public override fun onPause() { + super.onPause() + val currentProject = projectManager.currentProject + if (currentProject != null) { + ProjectSaver(currentProject, applicationContext).saveProjectAsync() + Utils.setLastUsedProjectName(applicationContext, currentProject.name) + } + } + + override fun onCreateOptionsMenu(menu: Menu): Boolean { + menuInflater.inflate(R.menu.menu_main_menu, menu) + val scratchConverter = getString(R.string.main_menu_scratch_converter) + val scratchConverterBeta = SpannableString( + scratchConverter + " " + getString(R.string.beta) + ) + + scratchConverterBeta.setSpan( + ForegroundColorSpan(resources.getColor(R.color.beta_label_color)), + scratchConverter.length, scratchConverterBeta.length, + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE + ) + menu.findItem(R.id.menu_scratch_converter).title = scratchConverterBeta + return true + } + + override fun onPrepareOptionsMenu(menu: Menu): Boolean { + menu.findItem(R.id.menu_login).isVisible = + !Utils.isUserLoggedIn(this) + menu.findItem(R.id.menu_logout).isVisible = + Utils.isUserLoggedIn(this) + if (!BuildConfig.FEATURE_SCRATCH_CONVERTER_ENABLED) { + menu.removeItem(R.id.menu_scratch_converter) + } + return true + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + R.id.menu_rate_app -> if (Utils.checkIsNetworkAvailableAndShowErrorMessage(this)) { + try { + startActivity( + Intent( + Intent.ACTION_VIEW, + Uri.parse("market://details?id=$packageName") + ) + ) + } catch (e: ActivityNotFoundException) { + Log.e(TAG, "onOptionsItemSelected: ", e) + ToastUtil.showError(this, R.string.main_menu_play_store_not_installed) + } + } + R.id.menu_terms_of_use -> TermsOfUseDialogFragment().show( + supportFragmentManager, + TermsOfUseDialogFragment.TAG + ) + R.id.menu_privacy_policy -> { + val browserIntent = Intent( + Intent.ACTION_VIEW, + Uri.parse(FlavoredConstants.PRIVACY_POLICY_URL) + ) + startActivity(browserIntent) + } + R.id.menu_about -> AboutDialogFragment().show( + supportFragmentManager, + AboutDialogFragment.TAG + ) + R.id.menu_scratch_converter -> if (Utils.checkIsNetworkAvailableAndShowErrorMessage(this)) { + startActivity(Intent(this, ScratchConverterActivity::class.java)) + } + R.id.settings -> startActivity(Intent(this, SettingsActivity::class.java)) + R.id.menu_login -> startActivity(Intent(this, SignInActivity::class.java)) + R.id.menu_logout -> { + Utils.logoutUser(this) + ToastUtil.showSuccess(this, R.string.logout_successful) + } + R.id.menu_help -> startActivity( + Intent( + Intent.ACTION_VIEW, + Uri.parse(CATROBAT_HELP_URL) + ) + ) + else -> return super.onOptionsItemSelected(item) + } + return true + } + + private fun prepareStandaloneProject() { + try { + val inputStream = assets.open(BuildConfig.START_PROJECT + ".zip") + val projectDir = File( + FlavoredConstants.DEFAULT_ROOT_DIRECTORY, + FileMetaDataExtractor.encodeSpecialCharsForFileSystem( + BuildConfig.PROJECT_NAME + ) + ) + ZipArchiver() + .unzip(inputStream, projectDir) + ProjectLoadTask(projectDir, this) + .setListener(this) + .execute() + } catch (e: IOException) { + Log.e("STANDALONE", "Cannot unpack standalone project: ", e) + } + } + + override fun onLoadFinished(success: Boolean) { + if (BuildConfig.FEATURE_APK_GENERATOR_ENABLED && success) { + startActivityForResult( + Intent(this, StageActivity::class.java), StageActivity.REQUEST_START_STAGE + ) + } + } + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + if (BuildConfig.FEATURE_APK_GENERATOR_ENABLED) { + if (requestCode == StageActivity.REQUEST_START_STAGE) { + finish() + } + } else { + super.onActivityResult(requestCode, resultCode, data) + } + } + + companion object { + val TAG = MainMenuActivity::class.java.simpleName + + @JvmField + var surveyCampaign: Survey? = null + } +} diff --git a/catroid/src/main/java/org/catrobat/catroid/ui/dialogs/TermsOfUseDialogFragment.java b/catroid/src/main/java/org/catrobat/catroid/ui/dialogs/TermsOfUseDialogFragment.java deleted file mode 100644 index 72348fc5d72..00000000000 --- a/catroid/src/main/java/org/catrobat/catroid/ui/dialogs/TermsOfUseDialogFragment.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2018 The Catrobat Team - * () - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * An additional term exception under section 7 of the GNU Affero - * General Public License, version 3, is available at - * http://developer.catrobat.org/license_additional_term - * - * This program 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.catrobat.catroid.ui.dialogs; - -import android.app.Dialog; -import android.content.DialogInterface; -import android.os.Bundle; -import android.text.Html; -import android.text.method.LinkMovementMethod; -import android.view.View; -import android.widget.TextView; - -import org.catrobat.catroid.R; -import org.catrobat.catroid.common.Constants; - -import androidx.appcompat.app.AlertDialog; -import androidx.fragment.app.DialogFragment; - -public class TermsOfUseDialogFragment extends DialogFragment { - - public static final String TAG = TermsOfUseDialogFragment.class.getSimpleName(); - - @Override - public Dialog onCreateDialog(Bundle bundle) { - View view = View.inflate(getActivity(), R.layout.dialog_terms_of_use, null); - - TextView termsOfUseTextView = view.findViewById(R.id.dialog_terms_of_use_text_view_info); - TextView termsOfUseUrlTextView = view.findViewById(R.id.dialog_terms_of_use_text_view_url); - - termsOfUseUrlTextView.setMovementMethod(LinkMovementMethod.getInstance()); - - String termsOfUseUrlStringText; - - AlertDialog.Builder termsOfUseDialogBuilder = new AlertDialog.Builder(getActivity()) - .setView(view) - .setTitle(R.string.dialog_terms_of_use_title); - - termsOfUseDialogBuilder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - dialog.dismiss(); - } - }); - - termsOfUseTextView.setText(R.string.dialog_terms_of_use_info); - termsOfUseUrlStringText = getString(R.string.dialog_terms_of_use_link_text); - - String termsOfUseUrl = getString(R.string.terms_of_use_link_template, Constants.CATROBAT_TERMS_OF_USE_URL, - termsOfUseUrlStringText); - - termsOfUseUrlTextView.setText(Html.fromHtml(termsOfUseUrl)); - - AlertDialog termsOfUseDialog = termsOfUseDialogBuilder.create(); - termsOfUseDialog.setCanceledOnTouchOutside(true); - - return termsOfUseDialog; - } -} diff --git a/catroid/src/main/java/org/catrobat/catroid/ui/dialogs/TermsOfUseDialogFragment.kt b/catroid/src/main/java/org/catrobat/catroid/ui/dialogs/TermsOfUseDialogFragment.kt new file mode 100644 index 00000000000..feea7991604 --- /dev/null +++ b/catroid/src/main/java/org/catrobat/catroid/ui/dialogs/TermsOfUseDialogFragment.kt @@ -0,0 +1,78 @@ +/* + * Catroid: An on-device visual programming system for Android devices + * Copyright (C) 2010-2018 The Catrobat Team + * () + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * An additional term exception under section 7 of the GNU Affero + * General Public License, version 3, is available at + * http://developer.catrobat.org/license_additional_term + * + * This program 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.catrobat.catroid.ui.dialogs + +import android.app.Dialog +import android.os.Bundle +import android.text.Html +import android.text.method.LinkMovementMethod +import android.view.LayoutInflater +import androidx.appcompat.app.AlertDialog +import androidx.fragment.app.DialogFragment +import org.catrobat.catroid.R +import org.catrobat.catroid.common.Constants +import org.catrobat.catroid.databinding.DialogTermsOfUseBinding + +class TermsOfUseDialogFragment : DialogFragment() { + private var _binding: DialogTermsOfUseBinding? = null + private val binding get() = _binding!! + + override fun onCreateDialog(bundle: Bundle?): Dialog { + _binding = DialogTermsOfUseBinding.inflate(LayoutInflater.from(activity)) + + val termsOfUseTextView = binding.dialogTermsOfUseTextViewInfo + val termsOfUseUrlTextView = binding.dialogTermsOfUseTextViewUrl + termsOfUseUrlTextView.movementMethod = LinkMovementMethod.getInstance() + + val termsOfUseUrlStringText = getString(R.string.dialog_terms_of_use_link_text) + val termsOfUseDialogBuilder = AlertDialog.Builder( + requireActivity() + ) + .setView(binding.root) + .setTitle(R.string.dialog_terms_of_use_title) + + termsOfUseDialogBuilder.setPositiveButton(R.string.ok) { dialog, id -> dialog.dismiss() } + + termsOfUseTextView.setText(R.string.dialog_terms_of_use_info) + + val termsOfUseUrl = getString( + R.string.terms_of_use_link_template, Constants.CATROBAT_TERMS_OF_USE_URL, + termsOfUseUrlStringText + ) + termsOfUseUrlTextView.text = Html.fromHtml(termsOfUseUrl) + + val termsOfUseDialog = termsOfUseDialogBuilder.create() + termsOfUseDialog.setCanceledOnTouchOutside(true) + + return termsOfUseDialog + } + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } + + companion object { + val TAG = TermsOfUseDialogFragment::class.java.simpleName + } +} diff --git a/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/dialog/AboutDialogFragment.java b/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/dialog/AboutDialogFragment.java deleted file mode 100644 index b6b74bcea11..00000000000 --- a/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/dialog/AboutDialogFragment.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2021 The Catrobat Team - * () - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * An additional term exception under section 7 of the GNU Affero - * General Public License, version 3, is available at - * http://developer.catrobat.org/license_additional_term - * - * This program 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.catrobat.catroid.ui.recyclerview.dialog; - -import android.app.Dialog; -import android.os.Bundle; -import android.text.Html; -import android.text.method.LinkMovementMethod; -import android.view.View; -import android.widget.TextView; - -import org.catrobat.catroid.BuildConfig; -import org.catrobat.catroid.R; -import org.catrobat.catroid.common.Constants; -import org.catrobat.catroid.utils.Utils; - -import androidx.appcompat.app.AlertDialog; -import androidx.fragment.app.DialogFragment; - -public class AboutDialogFragment extends DialogFragment { - - public static final String TAG = AboutDialogFragment.class.getSimpleName(); - - @Override - public Dialog onCreateDialog(Bundle bundle) { - View view = View.inflate(getActivity(), R.layout.dialog_about, null); - - TextView developerUrlView = view.findViewById(R.id.dialog_about_text_view_url); - developerUrlView.setMovementMethod(LinkMovementMethod.getInstance()); - - String developerUrl = getString(R.string.about_link_template, Constants.ABOUT_POCKETCODE_LICENSE_URL, - getString(R.string.dialog_about_license_link_text)); - - developerUrlView.setText(Html.fromHtml(developerUrl)); - - TextView aboutCatrobatView = view.findViewById(R.id.dialog_about_text_catrobat_url); - aboutCatrobatView.setMovementMethod(LinkMovementMethod.getInstance()); - - String aboutCatrobatUrl = getString(R.string.about_link_template, Constants.CATROBAT_ABOUT_URL, - getString(R.string.dialog_about_catrobat_link_text)); - - aboutCatrobatView.setText(Html.fromHtml(aboutCatrobatUrl)); - - TextView aboutVersionNameTextView = view.findViewById(R.id.dialog_about_text_view_version_name); - String versionCode = BuildConfig.FLAVOR.equals("pocketCodeBeta") ? "-" + BuildConfig.VERSION_CODE : ""; - String versionName = getString(R.string.app_name) + versionCode + " " + getString(R.string.dialog_about_version) - + " " + getString(R.string.android_version_prefix) + Utils.getVersionName(getActivity()); - aboutVersionNameTextView.setText(versionName); - - TextView aboutCatrobatVersionTextView = view.findViewById(R.id.dialog_about_text_view_catrobat_version_name); - double catrobatVersion = Constants.CURRENT_CATROBAT_LANGUAGE_VERSION; - String catrobatVersionName = - getString(R.string.dialog_about_catrobat_language_version) + ": " + catrobatVersion; - aboutCatrobatVersionTextView.setText(catrobatVersionName); - - return new AlertDialog.Builder(getActivity()) - .setTitle(R.string.dialog_about_title) - .setView(view) - .setPositiveButton(R.string.ok, null) - .create(); - } -} diff --git a/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/dialog/AboutDialogFragment.kt b/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/dialog/AboutDialogFragment.kt new file mode 100644 index 00000000000..a457b5bb483 --- /dev/null +++ b/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/dialog/AboutDialogFragment.kt @@ -0,0 +1,91 @@ +/* + * Catroid: An on-device visual programming system for Android devices + * Copyright (C) 2010-2021 The Catrobat Team + * () + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * An additional term exception under section 7 of the GNU Affero + * General Public License, version 3, is available at + * http://developer.catrobat.org/license_additional_term + * + * This program 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.catrobat.catroid.ui.recyclerview.dialog + +import android.app.Dialog +import android.os.Bundle +import android.text.Html +import android.text.method.LinkMovementMethod +import android.view.LayoutInflater +import androidx.appcompat.app.AlertDialog +import androidx.fragment.app.DialogFragment +import org.catrobat.catroid.BuildConfig +import org.catrobat.catroid.R +import org.catrobat.catroid.common.Constants +import org.catrobat.catroid.databinding.DialogAboutBinding +import org.catrobat.catroid.utils.Utils + +class AboutDialogFragment : DialogFragment() { + private var _binding: DialogAboutBinding? = null + private val binding get() = _binding!! + + override fun onCreateDialog(bundle: Bundle?): Dialog { + _binding = DialogAboutBinding.inflate(LayoutInflater.from(activity)) + + val developerUrlView = binding.dialogAboutTextViewUrl + developerUrlView.movementMethod = LinkMovementMethod.getInstance() + val developerUrl = getString( + R.string.about_link_template, Constants.ABOUT_POCKETCODE_LICENSE_URL, + getString(R.string.dialog_about_license_link_text) + ) + developerUrlView.text = Html.fromHtml(developerUrl) + + val aboutCatrobatView = binding.dialogAboutTextCatrobatUrl + aboutCatrobatView.movementMethod = LinkMovementMethod.getInstance() + val aboutCatrobatUrl = getString( + R.string.about_link_template, Constants.CATROBAT_ABOUT_URL, + getString(R.string.dialog_about_catrobat_link_text) + ) + aboutCatrobatView.text = Html.fromHtml(aboutCatrobatUrl) + + val aboutVersionNameTextView = binding.dialogAboutTextViewCatrobatVersionName + val versionCode = + if (BuildConfig.FLAVOR == "pocketCodeBeta") "-" + BuildConfig.VERSION_CODE else "" + val versionName = + getString(R.string.app_name) + versionCode + " " + getString(R.string.dialog_about_version) + " " + getString(R.string.android_version_prefix) + Utils.getVersionName( + activity + ) + aboutVersionNameTextView.text = versionName + + val aboutCatrobatVersionTextView = binding.dialogAboutTextViewCatrobatVersionName + val catrobatVersion = Constants.CURRENT_CATROBAT_LANGUAGE_VERSION + val catrobatVersionName = + getString(R.string.dialog_about_catrobat_language_version) + ": " + catrobatVersion + aboutCatrobatVersionTextView.text = catrobatVersionName + + return AlertDialog.Builder(requireActivity()) + .setTitle(R.string.dialog_about_title) + .setView(binding.root) + .setPositiveButton(R.string.ok, null) + .create() + } + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } + + companion object { + val TAG = AboutDialogFragment::class.java.simpleName + } +}