Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PAINTROID-672: Refactor MediaGalleryWebViewClient to kotlin #1336

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Paintroid/src/main/java/org/catrobat/paintroid/FileIO.kt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ object FileIO {
ORA("ora"),
CATROBAT("catrobat-image");


fun toExtension(): String = ".$value"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.catrobat.paintroid



import java.io.File
import java.lang.IllegalArgumentException

Expand All @@ -28,7 +30,14 @@ class PaintroidApplication private constructor() {
var cacheDir: File? = null
}

init {
throw IllegalArgumentException()
init {
throw IllegalArgumentException()
}
}
}







Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ interface MainActivityContracts {
fun checkForTemporaryFile(): Boolean

fun setColorHistoryAfterLoadImage(colorHistory: ColorHistory?)

}

interface Model {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,28 @@ import org.catrobat.paintroid.FileIO.FileType.PNG
import org.catrobat.paintroid.FileIO.FileType.JPG
import org.catrobat.paintroid.FileIO.FileType.CATROBAT
import org.catrobat.paintroid.FileIO.FileType.ORA



import org.catrobat.paintroid.R

import java.util.Locale








private const val STANDARD_FILE_NAME = "image"
private const val SET_NAME = "setName"
private const val PERMISSION = "permission"
private const val IS_EXPORT = "isExport"




class SaveInformationDialog :
MainActivityDialogFragment(),
OnItemSelectedListener,
Expand Down Expand Up @@ -118,6 +132,7 @@ class SaveInformationDialog :
FileIO.storeImageUri = null
if (FileIO.checkFileExists(FileIO.fileType, FileIO.defaultFileName, requireContext().contentResolver)) {
presenter.showOverwriteDialog(permission, isExport)

} else {
presenter.switchBetweenVersions(permission, isExport)
}
Expand All @@ -127,8 +142,12 @@ class SaveInformationDialog :
.create()
}



private fun initViews(customLayout: View) {
initSpecificFormatLayout(customLayout)


initJpgView()
initSeekBar()
initPercentage()
Expand All @@ -141,6 +160,10 @@ class SaveInformationDialog :
specificFormatLayout = view.findViewById(R.id.pocketpaint_save_format_specific_options)
}





private fun initJpgView() {
jpgView = inflater.inflate(
R.layout.dialog_pocketpaint_save_jpg_sub_dialog,
Expand Down Expand Up @@ -168,11 +191,14 @@ class SaveInformationDialog :
JPG -> presenter.showJpgInformationDialog()
ORA -> presenter.showOraInformationDialog()
CATROBAT -> presenter.showCatrobatInformationDialog()

else -> presenter.showPngInformationDialog()
}
}
}



private fun initSpinner(view: View) {
spinner = view.findViewById(R.id.pocketpaint_save_dialog_spinner)
val spinnerArray = FileType.values().map { it.value }
Expand Down Expand Up @@ -204,6 +230,7 @@ class SaveInformationDialog :
JPG -> spinner.setSelection(JPG.ordinal)
ORA -> spinner.setSelection(ORA.ordinal)
CATROBAT -> spinner.setSelection(CATROBAT.ordinal)

else -> spinner.setSelection(PNG.ordinal)
}
}
Expand All @@ -212,8 +239,10 @@ class SaveInformationDialog :
when (parent?.getItemAtPosition(position).toString().toLowerCase(Locale.getDefault())) {
JPG.value -> setFileDetails(Bitmap.CompressFormat.JPEG, JPG)
PNG.value -> setFileDetails(Bitmap.CompressFormat.PNG, PNG)

ORA.value -> setFileDetails(Bitmap.CompressFormat.PNG, ORA)
CATROBAT.value -> setFileDetails(Bitmap.CompressFormat.PNG, CATROBAT)

}
}

Expand All @@ -226,3 +255,6 @@ class SaveInformationDialog :
override fun onStartTrackingTouch(seekBar: SeekBar) = Unit
override fun onStopTrackingTouch(seekBar: SeekBar) = Unit
}



Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class DrawableFactory {
DrawableShape.OVAL -> OvalDrawable()
DrawableShape.HEART -> HeartDrawable()
DrawableShape.STAR -> StarDrawable()

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ open class DrawingSurface : SurfaceView, SurfaceHolder.Callback {
drawingThread?.stop()
}


private inner class DrawLoop : Runnable {
val holder: SurfaceHolder = getHolder()
override fun run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class DefaultShapeToolOptionsView(rootView: ViewGroup) : ShapeToolOptionsView {
private val shapeToolDialogTitle: AppCompatTextView
private val shapeToolFillOutline: AppCompatTextView


init {
val inflater = LayoutInflater.from(rootView.context)
val shapeToolView = inflater.inflate(R.layout.dialog_pocketpaint_shapes, rootView)
Expand All @@ -74,6 +75,7 @@ class DefaultShapeToolOptionsView(rootView: ViewGroup) : ShapeToolOptionsView {
outlineTextView = findViewById(R.id.pocketpaint_outline_view_text_view)
outlineWidthSeekBar = findViewById(R.id.pocketpaint_shape_stroke_width_seek_bar)
outlineWidthEditText = findViewById(R.id.pocketpaint_shape_outline_edit)

}
outlineWidthEditText.filters =
arrayOf<InputFilter>(DefaultNumberRangeFilter(MIN_VAL, MAX_VAL))
Expand All @@ -89,6 +91,8 @@ class DefaultShapeToolOptionsView(rootView: ViewGroup) : ShapeToolOptionsView {
circleButton.setOnClickListener { onShapeClicked(DrawableShape.OVAL) }
heartButton.setOnClickListener { onShapeClicked(DrawableShape.HEART) }
starButton.setOnClickListener { onShapeClicked(DrawableShape.STAR) }


fillButton.setOnClickListener { onDrawTypeClicked(DrawableStyle.FILL) }
outlineButton.setOnClickListener { onDrawTypeClicked(DrawableStyle.STROKE) }
outlineWidthSeekBar.setOnSeekBarChangeListener(object : OnSeekBarChangeListener {
Expand Down Expand Up @@ -141,7 +145,9 @@ class DefaultShapeToolOptionsView(rootView: ViewGroup) : ShapeToolOptionsView {
}

private fun resetShapeActivated() {
val buttons = arrayOf<View>(squareButton, circleButton, heartButton, starButton)
val buttons = arrayOf<View>(squareButton, circleButton, heartButton, starButton,)


for (button in buttons) {
button.isSelected = false
}
Expand Down Expand Up @@ -175,6 +181,7 @@ class DefaultShapeToolOptionsView(rootView: ViewGroup) : ShapeToolOptionsView {
starButton.isSelected = true
setShapeToolDialogTitle(R.string.shape_tool_dialog_star_title)
}

}
}

Expand All @@ -184,13 +191,17 @@ class DefaultShapeToolOptionsView(rootView: ViewGroup) : ShapeToolOptionsView {
circleButtonResource: Int,
heartButtonResource: Int,
starButtonResource: Int,


visibility: Int
) {
shapeToolFillOutline.setText(fillTitle)
squareButton.setImageResource(squareButtonResource)
circleButton.setImageResource(circleButtonResource)
heartButton.setImageResource(heartButtonResource)
starButton.setImageResource(starButtonResource)


outlineWidthSeekBar.visibility = visibility
outlineWidthEditText.visibility = visibility
outlineView.visibility = visibility
Expand All @@ -208,6 +219,7 @@ class DefaultShapeToolOptionsView(rootView: ViewGroup) : ShapeToolOptionsView {
R.drawable.ic_pocketpaint_circle,
R.drawable.ic_pocketpaint_heart,
R.drawable.ic_pocketpaint_star,

View.GONE
)
}
Expand All @@ -219,6 +231,7 @@ class DefaultShapeToolOptionsView(rootView: ViewGroup) : ShapeToolOptionsView {
R.drawable.ic_pocketpaint_circle_out,
R.drawable.ic_pocketpaint_heart_out,
R.drawable.ic_pocketpaint_star_out,

View.VISIBLE
)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2018 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.catrobat.paintroid.web

import android.app.ProgressDialog
import android.graphics.Bitmap
import android.webkit.WebView
import android.webkit.WebViewClient
import org.catrobat.paintroid.R

class MediaGalleryWebViewClient(private val callback: WebClientCallback) : WebViewClient() {
private var webViewLoadingDialog: ProgressDialog? = null

interface WebClientCallback {
fun finish()
}

override fun onPageStarted(view: WebView, urlClient: String, favicon: Bitmap) {
if (webViewLoadingDialog == null && !urlClient.matches("https://share.catrob.at/pocketcode/".toRegex())) {
webViewLoadingDialog = ProgressDialog(view.context, R.style.WebViewLoadingCircle)
webViewLoadingDialog!!.setCancelable(true)
webViewLoadingDialog!!.setCanceledOnTouchOutside(false)
webViewLoadingDialog!!.setProgressStyle(android.R.style.Widget_ProgressBar_Small)
webViewLoadingDialog!!.show()
} else {
callback.finish()
}
}

override fun onPageFinished(view: WebView, url: String) {
if (webViewLoadingDialog != null) {
webViewLoadingDialog!!.dismiss()
webViewLoadingDialog = null
}
}

override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
return false
}

override fun onReceivedError(
view: WebView,
errorCode: Int,
description: String,
failingUrl: String
) {
callback.finish()
}
}
4 changes: 4 additions & 0 deletions Paintroid/src/main/res/layout/dialog_pocketpaint_save.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,8 @@
android:clipChildren="false"
android:clipToPadding="false" />





</LinearLayout>
Loading