-
-
Notifications
You must be signed in to change notification settings - Fork 565
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
Updated RateOrShareFragment elements to disappear on some config options. #553
base: master
Are you sure you want to change the base?
Changes from all commits
1a2b016
9c4144c
03d81c4
3a79070
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,7 @@ | |
import com.google.android.play.core.review.ReviewInfo; | ||
import com.google.android.play.core.review.ReviewManager; | ||
import com.google.android.play.core.review.ReviewManagerFactory; | ||
import com.iiordanov.util.CustomClientConfigFileReader; | ||
import com.undatech.opaque.AbstractDrawableData; | ||
import com.undatech.opaque.ConnectionSetupActivity; | ||
import com.undatech.remoteClientUi.R; | ||
|
@@ -76,6 +77,7 @@ | |
import java.io.StringWriter; | ||
import java.io.Writer; | ||
import java.lang.reflect.Field; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
import java.util.concurrent.Executor; | ||
import java.util.concurrent.Executors; | ||
|
@@ -275,6 +277,32 @@ public static boolean isOpaque(Context context) { | |
return packageName.toLowerCase().contains("opaque"); | ||
} | ||
|
||
public static String getStringConfigAttribute(Map<String, Map> configData, String configDataKey, String configDataKeyChild, String childAttribute) throws NullPointerException { | ||
try { | ||
String attr = (String) ((Map) configData.get(configDataKey).get(configDataKeyChild)).get(childAttribute); | ||
return attr; | ||
} | ||
catch (NullPointerException e) { | ||
throw e; | ||
} | ||
} | ||
|
||
public static void setVisibilityForViewElementsViaConfig(Context context, Map<String, Map> configData, String configDataKey, View view) throws NullPointerException { | ||
try { | ||
String packageName = Utils.pName(context); | ||
Map<String, Integer> visibility = (Map<String, Integer>) configData.get(configDataKey).get("visibility"); | ||
|
||
for (String s : visibility.keySet()) { | ||
int resID = context.getResources().getIdentifier(s, "id", packageName); | ||
View viewElement = view.findViewById(resID); | ||
viewElement.setVisibility(visibility.get(s)); | ||
} | ||
} | ||
catch (NullPointerException e) { | ||
throw e; | ||
} | ||
Comment on lines
+301
to
+303
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, why catch at all? |
||
} | ||
|
||
public static Class getConnectionSetupClass(Context context) { | ||
String packageName = Utils.pName(context); | ||
boolean custom = isCustom(context); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,8 +27,10 @@ import android.widget.Button | |
import android.widget.TableLayout | ||
import android.widget.TextView | ||
import androidx.fragment.app.DialogFragment | ||
import com.iiordanov.bVNC.App | ||
import com.iiordanov.bVNC.Utils | ||
import com.undatech.remoteClientUi.R | ||
import java.io.IOException | ||
|
||
class RateOrShareFragment : DialogFragment() { | ||
private var layout: TableLayout? = null | ||
|
@@ -47,11 +49,11 @@ class RateOrShareFragment : DialogFragment() { | |
savedInstanceState: Bundle? | ||
): View? { | ||
Log.d(TAG, "onCreateView called") | ||
dialog?.setTitle(getString(R.string.action_rate_or_share_app)) | ||
setTitle() | ||
val v = inflater.inflate(R.layout.rateorshare, container, false) | ||
layout = v.findViewById<View>(R.id.layout) as TableLayout | ||
donationButton = v.findViewById(R.id.buttonDonate); | ||
previousVersionsButton = v.findViewById(R.id.buttonPreviousVersions); | ||
donationButton = v.findViewById(R.id.buttonDonate) | ||
previousVersionsButton = v.findViewById(R.id.buttonPreviousVersions) | ||
if (!Utils.isFree(activity)) { | ||
donationButton?.visibility = View.GONE | ||
} | ||
|
@@ -60,10 +62,53 @@ class RateOrShareFragment : DialogFragment() { | |
} | ||
versionAndCode = v.findViewById<View>(R.id.versionAndCode) as TextView | ||
versionAndCode?.text = Utils.getVersionAndCode(v.context) | ||
|
||
setVisibilityOfElements(v) | ||
return v | ||
} | ||
|
||
fun setTitle() { | ||
if (Utils.isCustom(context)){ | ||
try { | ||
dialog?.setTitle( | ||
getString( | ||
requireContext().resources.getIdentifier( | ||
Utils.getStringConfigAttribute(App.configFileReader.configData, TAG.replaceFirstChar { it.lowercase() }, "title", "key"), | ||
"string", | ||
Utils.pName(context) | ||
) | ||
) | ||
) | ||
return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer having no random returns within methods. In both cases you're calling dialog?.setTitle() with a string parameter. Have the if/else statement set that string parameter appropriately, and call dialog?.setTitle(thatStringParameter) at the end of the method. |
||
} | ||
catch (e: Exception) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of catching an Exception and then re-throwing "if it's an NPE" later, why not just catch only NullPointerException and let any other kind of exception get automatically not caught and thrown? |
||
isCustomException(e) | ||
} | ||
} | ||
dialog?.setTitle(getString(R.string.action_rate_or_share_app)) | ||
} | ||
|
||
fun setVisibilityOfElements(v: View) { | ||
if (Utils.isCustom(context)){ | ||
try { | ||
Utils.setVisibilityForViewElementsViaConfig(context, App.configFileReader.configData, TAG.replaceFirstChar { it.lowercase() }, v) | ||
} | ||
catch (e: Exception) { | ||
isCustomException(e) | ||
} | ||
} | ||
} | ||
|
||
fun isCustomException(e: Exception) { | ||
when (e) { | ||
is NullPointerException -> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To complement the previous comment - basically you've caught any exception and then have logic to check whether it's an NPE and re-throw if it's not. It's significantly simpler to just catch only the NPE instead. |
||
Log.e(TAG, "Error referencing attribute in config file.") | ||
} | ||
else -> throw e | ||
} | ||
Log.e(TAG, "Printing Stack Trace") | ||
e.printStackTrace() | ||
} | ||
|
||
companion object { | ||
var TAG = "RateOrShareFragment" | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you catching the NPE and then just throwing it? Why not just not catch it in the first place?