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

Updated RateOrShareFragment elements to disappear on some config options. #553

Open
wants to merge 4 commits into
base: master
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
17 changes: 17 additions & 0 deletions bVNC/src/main/java/com/iiordanov/bVNC/App.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
package com.iiordanov.bVNC;

import android.content.Context;
import android.util.Log;

import androidx.appcompat.app.AppCompatDelegate;
import androidx.multidex.MultiDex;
import androidx.multidex.MultiDexApplication;

import java.io.IOException;
import java.lang.ref.WeakReference;

import com.iiordanov.util.CustomClientConfigFileReader;

public class App extends MultiDexApplication {
private final static String TAG = "App";

public static boolean debugLog = false;
private static WeakReference<Context> context;
private Database database;

public static CustomClientConfigFileReader configFileReader;

public static Context getContext() {
return context.get();
}
Expand All @@ -31,10 +38,20 @@ public void onCreate() {
Constants.DEFAULT_PROTOCOL_PORT = Utils.getDefaultPort(this);
database = new Database(this);
context = new WeakReference<Context>(this);
if(Utils.isCustom(getApplicationContext())){
try {
configFileReader = new CustomClientConfigFileReader(
getApplicationContext().getAssets().open(Utils.pName(getApplicationContext()) + ".yaml"));
} catch (IOException e) {
Log.e(TAG, "Error opening config file from assets.");
}
}
debugLog = Utils.querySharedPreferenceBoolean(getApplicationContext(), "moreDebugLoggingTag");
}

public Database getDatabase() {
return database;
}

public static CustomClientConfigFileReader getConfigFileReader(){ return configFileReader;}
}
7 changes: 1 addition & 6 deletions bVNC/src/main/java/com/iiordanov/bVNC/CustomVnc.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ public void onCreate(Bundle icicle) {
Map<String, Map> configData = configFileReader.getConfigData();
Map<String, Integer> visibility = (Map<String, Integer>) configData.get("mainConfiguration").get("visibility");

for (String s : visibility.keySet()) {
Log.d(TAG, s);
int resID = getResources().getIdentifier(s, "id", packageName);
view = findViewById(resID);
view.setVisibility(visibility.get(s));
}
Utils.setVisibilityForViewElementsViaConfig(this, App.getConfigFileReader().getConfigData(),"mainConfiguration", findViewById(android.R.id.content).getRootView());

Locale current = getResources().getConfiguration().locale;
String currentLanguage = current.getLanguage();
Expand Down
28 changes: 28 additions & 0 deletions bVNC/src/main/java/com/iiordanov/bVNC/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Comment on lines +285 to +287
Copy link
Owner

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?

}

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
Copy link
Owner

Choose a reason for hiding this comment

The 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The 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) {
Copy link
Owner

Choose a reason for hiding this comment

The 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 -> {
Copy link
Owner

Choose a reason for hiding this comment

The 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"
}
Expand Down
1 change: 1 addition & 0 deletions bVNC/src/main/res/layout/rateorshare.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<TableRow android:gravity="center">

<TextView
android:id="@+id/love_our_work"
android:text="@string/love_our_work"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
Expand Down
25 changes: 22 additions & 3 deletions bVNC/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<string name="action_edit_default_settings">編集デフォルト設定</string>
<string name="action_export_settings">エクスポート設定</string>
<string name="action_delete_connection">接続削除</string>
<string name="action_rate_or_share_app">ヘルプ、評価、シェア</string>
<string name="get_help">ヘルプ</string>
<string name="opaque_app_name">不透明</string>
<string name="opaque_app_name_beta">不透明なベータ</string>
<string name="advanced_settings">高度な設定</string>
Expand Down Expand Up @@ -218,7 +220,7 @@
<string name="error_spice_unable_to_connect">接続/認証ができません。サーバーアドレス、パスワード、認証局とサブジェクトを確認してください。</string>
<string name="error_ssh_could_not_exec_command">リモートコマンドを実行できませんでした。</string>
<string name="error_ssh_could_not_send_sudo_pwd">sudoパスワードを送信できませんでした。</string>
<string name="error_ssh_hostkey_changed">エラー!サーバーホストキーが変更されました。意図的に変更された場合は、一度接続を削除してから再試行してください。そうでない場合、中間者攻撃の可能性があります。</string>
<string name="error_ssh_hostkey_changed">エラー!サーバーのホストキーが変更されました。意図的に変更した場合、続行してください。そうでない場合は、中間者攻撃の可能性があります。</string>
<string name="error_ssh_kbd_auth_method_unavail">SSHサーバーは、 \"password\"と\"keyboard-interactive\"両方の認証方式に非対応です。 或いは\"publickey\"方式を先に実行させる必要があります。少なくとも、どちらか1つを許可するよう設定してください。又は、bVNC側を再設定してください。有効な認証方式:</string>
<string name="error_ssh_key_auth_fail">鍵ペアによるSSHサーバーへの認証に失敗しました。SSHユーザー名を確認してください。また、パブリックキーがリモート側の「認証済みキーファイル」に入っていることを確認してください。</string>
<string name="error_ssh_keypair_decryption_failure">鍵ペアの解読に失敗しました。メイン画面の\'SSH Passphrase\'フィールドに、パスフレーズが正しく入力されていることを確認してください。</string>
Expand Down Expand Up @@ -843,6 +845,7 @@ aSPICEで対応済み機能は以下の通り:
<string name="enter_vnc_credentials">VNCクレデンシャルを入力してください</string>
<string name="enter_vnc_password">VNCパスワードを入力してください</string>
<string name="enter_rdp_credentials">RDPクレデンシャルを入力してください</string>
<string name="enter_gateway_credentials">ゲートウェイの認証情報を入力してください</string>
<string name="enter_spice_password">SPICEパスワードを入力してください</string>
<string name="enter_passphrase_title">キーパスフレーズを入力してください</string>
<string name="enter_passphrase">キーパスフレーズを入力してください</string>
Expand All @@ -865,7 +868,9 @@ aSPICEで対応済み機能は以下の通り:

-詳細設定:このセクションでは、ローカルデバイス、プロトコル、およびパフォーマンスの微調整を確認できます。"</string>
<string name="help">ヘルプ</string>
<string name="need_help">ヘルプが必要ですか?</string>
<string name="support_forum">サポートフォーラム</string>
<string name="email_us">Emailを送る 📧</string>
<string name="report_bug">バグを報告</string>
<string name="download_from_server">サーバーからダウンロード</string>
<string name="import_from_file">ファイルからインポート</string>
Expand All @@ -874,6 +879,20 @@ aSPICEで対応済み機能は以下の通り:
<string name="rdp_adv_gfxh264">RDP Gfx H264</string>
<string name="more_debug_logging">その他のデバッグログ</string>
<string name="prefer_sending_unicode">Unicode入力(Windowsのみ)</string>
<string name="hide_connection_thumbnails">サムネイル非表示</string>
<string name="show_only_connection_nicknames">ニックネーム表示</string>
<string name="hide_connection_thumbnails">接続サムネイルを隠す</string>
<string name="show_only_connection_nicknames">接続ニックネームのみを表示</string>
<string name="love_our_work">このアプリを気に入りましたか?</string>
<string name="rate_app">評価する ⭐⭐⭐⭐⭐</string>
<string name="share_app">シェアする 🔗</string>
<string name="share_app_toast">このアプリをSNSで友達にシェア!</string>
<string name="donate_app">寄付する ❤</string>
<string name="more_apps">その他のアプリ 📱</string>
<string name="previous_versions">バージョン履歴 ⍼</string>
<string name="keyboard_type">ソフトウェアキーボードのタイプ</string>
<string name="pref_keyboard_type_label_TYPE_NULL">デフォルト (TYPE_NULL)</string>
<string name="pref_keyboard_type_label_VISIBLE_PASSWORD">テキスト/数字入力サポートなし(VISIBLE_PASSWORD)</string>
<string name="pref_keyboard_type_label_TYPE_CLASS_TEXT">テキスト入力サポートあり (TYPE_CLASS_TEXT)</string>
<string name="no_application_to_handle_vpn">この接続は、外部アプリ経由でVPNを起動するように設定されています。起動するにはMorpheuslyのようなアプリをインストールする必要があります。</string>
<string name="vnc_viewer_started">VNCビューワーが開始しました</string>
<string name="enable_gateway">ゲートウェイを有効にする</string>
</resources>
25 changes: 22 additions & 3 deletions bVNC/src/main/res/values-ko/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<string name="action_edit_default_settings">기본 설정 편집</string>
<string name="action_export_settings">내보내기 설정</string>
<string name="action_delete_connection">연결 삭제</string>
<string name="action_rate_or_share_app">도움말, 평가, 공유</string>
<string name="get_help">도움말</string>
<string name="opaque_app_name">불투명</string>
<string name="opaque_app_name_beta">불투명한 베타</string>
<string name="advanced_settings">고급 설정</string>
Expand Down Expand Up @@ -220,7 +222,7 @@
<string name="error_spice_unable_to_connect">연결/인증 수 없습니다. 서버 주소, Password, 인증 기관 과 서브젝트를 확인하십시오.</string>
<string name="error_ssh_could_not_exec_command">리모트 명령을 실행할 수 없습니다.</string>
<string name="error_ssh_could_not_send_sudo_pwd">sudo Password를 전송할 수 없습니다.</string>
<string name="error_ssh_hostkey_changed">에러! 서버 호스트 키가 변경되었습니다.의도적으로 변경된 경우는 한번 연결을 제거하고 재시행하십시오.그렇지 않은 경우 중간자 공격의 가능성이 있습니다.</string>
<string name="error_ssh_hostkey_changed">오류! 서버 호스트 키가 변경되었습니다. 의도적으로 변경한 경우 계속하십시오. 그렇지 않으면 중간자 공격의 가능성이 있습니다.</string>
<string name="error_ssh_kbd_auth_method_unavail">SSH 서버는 \"password\" 과 \"keyboard-interactive\" 양쪽의 인증 방식으로 대응하지 않습니다. 혹은 \"publickey \" 방식을 먼저 실행해야합니다. 적어도 어느 하나를 허용하도록 설정하십시오. 또는 본 애플리케이션측을 재 설정하십시오. 유효한 인증 방식:</string>
<string name="error_ssh_key_auth_fail">key-pair(공개 키와 비밀 키)에 의한 SSH서버에 인증에 실패했습니다.SSH 사용자 이름을 확인하십시오.또한 공개 키가 리모트의 "인증 된 키 파일"에 들어 있는지 확인하십시오.</string>
<string name="error_ssh_keypair_decryption_failure">key-pair(공개 키와 비밀 키)의 해독에 실패했습니다.메인 화면의 \'SSH Passphrase\' 필드에 passphrase(암호 문구)를 올바르게 입력되어 있는지 확인하십시오.</string>
Expand Down Expand Up @@ -824,6 +826,7 @@ aSPICEで의 대응 기능는 이하와 같다 :
<string name="enter_vnc_credentials">VNC credentials(자격 증명)을 입력하세요.</string>
<string name="enter_vnc_password">VNC 비밀번호를 입력하세요.</string>
<string name="enter_rdp_credentials">RDP credentials(자격 증명)을 입력하세요.</string>
<string name="enter_gateway_credentials">게이트웨이 인증 정보를 입력하세요.</string>
<string name="enter_spice_password">SPICE 비밀번호를 입력하세요.</string>
<string name="enter_passphrase_title">키 패스프레이즈를 입력하세요.</string>
<string name="enter_passphrase">키 패스프레이즈를 입력하세요.</string>
Expand All @@ -846,7 +849,9 @@ aSPICEで의 대응 기능는 이하와 같다 :

- 고급 설정: 이 섹션에서는 로컬 장치, 프로토콜 및 성능의 미세 조정을 확인할 수 있습니다."</string>
<string name="help">도움</string>
<string name="need_help">도움이 필요하십니까?</string>
<string name="support_forum">지원 포럼</string>
<string name="email_us">이메일 보내기 📧</string>
<string name="report_bug">버그보고</string>
<string name="download_from_server">서버에서 다운로드</string>
<string name="import_from_file">파일에서 가져오기</string>
Expand All @@ -855,6 +860,20 @@ aSPICEで의 대응 기능는 이하와 같다 :
<string name="rdp_adv_gfxh264">RDP Gfx H264</string>
<string name="more_debug_logging">기타 디버그 로그</string>
<string name="prefer_sending_unicode">유니코드 입력(Windows만 해당)</string>
<string name="hide_connection_thumbnails">썸네일 비표시</string>
<string name="show_only_connection_nicknames">닉네임 표시</string>
<string name="hide_connection_thumbnails">연결 썸네일 숨기기</string>
<string name="show_only_connection_nicknames">연결 닉네임만 표시</string>
<string name="love_our_work">이 앱이 마음에 드셨습니까?</string>
<string name="rate_app">평가 ⭐⭐⭐⭐⭐</string>
<string name="share_app">공유 🔗</string>
<string name="share_app_toast">앱 링크를 SNS로 친구에게 공유</string>
<string name="donate_app">기부하다 ❤</string>
<string name="more_apps">기타 앱 📱</string>
<string name="previous_versions">버전 기록 ⍼</string>
<string name="keyboard_type">소프트웨어 키보드 타입</string>
<string name="pref_keyboard_type_label_TYPE_NULL">디폴트(TYPE_NULL)</string>
<string name="pref_keyboard_type_label_VISIBLE_PASSWORD">텍스트/숫자 입력 지원 없음(VISIBLE_PASSWORD)</string>
<string name="pref_keyboard_type_label_TYPE_CLASS_TEXT">텍스트 입력 지원 있음(TYPE_CLASS_TEXT)</string>
<string name="no_application_to_handle_vpn">이 연결은 외부 앱을 통해 VPN을 시작하도록 구성되어 있습니다. 시작하려면 Morpheusly와 같은 앱을 설치가 필요합니다.</string>
<string name="vnc_viewer_started">VNC 뷰어가 시작되었습니다.</string>
<string name="enable_gateway">게이트웨이를 활성화</string>
</resources>
Loading