Skip to content

Commit

Permalink
Merge pull request nextcloud#12795 from nextcloud/refactor/main-app-g…
Browse files Browse the repository at this point in the history
…et-string-by-alper

Simplify main app get string logic
  • Loading branch information
tobiasKaminsky authored Apr 2, 2024
2 parents 1caf721 + 62167a4 commit f4f9f0a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
21 changes: 14 additions & 7 deletions app/src/main/java/com/owncloud/android/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,13 @@ && getAppContext() != null) {
}
}

public static String string(int id) {
return getAppContext().getString(id);
}

public static String string(int id, Object args) {
return getAppContext().getString(id, args);
}

public static Context getAppContext() {
return MainApp.mContext;
Expand Down Expand Up @@ -674,32 +681,32 @@ public static String getAccountType(Context context) {
// From AccountAuthenticator
// public static final String AUTHORITY = "org.owncloud";
public static String getAuthority() {
return getAppContext().getResources().getString(R.string.authority);
return string(R.string.authority);
}

// From AccountAuthenticator
// public static final String AUTH_TOKEN_TYPE = "org.owncloud";
public static String getAuthTokenType() {
return getAppContext().getResources().getString(R.string.authority);
return string(R.string.authority);
}

// From ProviderMeta
// public static final String DB_FILE = "owncloud.db";
public static String getDBFile() {
return getAppContext().getResources().getString(R.string.db_file);
return string(R.string.db_file);
}

// From ProviderMeta
// private final String mDatabaseName = "ownCloud";
public static String getDBName() {
return getAppContext().getResources().getString(R.string.db_name);
return string(R.string.db_name);
}

/**
* name of data_folder, e.g., "owncloud"
*/
public static String getDataFolder() {
return getAppContext().getResources().getString(R.string.data_folder);
return string(R.string.data_folder);
}

public static void showOnlyFilesOnDevice(boolean state) {
Expand All @@ -725,8 +732,8 @@ public static String getUserAgent() {

// user agent
private static String getUserAgent(@StringRes int agent) {
String appString = getAppContext().getResources().getString(agent);
String brandedName = getAppContext().getString(R.string.name_for_branded_user_agent);
String appString = string(agent);
String brandedName = string(R.string.name_for_branded_user_agent);
String packageName = getAppContext().getPackageName();
String version = "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public boolean canProvideStoragePoints() {
public Vector<StoragePoint> getAvailableStoragePoint() {
Vector<StoragePoint> result = new Vector<>();

final String defaultStringDesc = MainApp.getAppContext().getString(R.string.storage_description_default);
final String defaultStringDesc = MainApp.string(R.string.storage_description_default);
// Add private internal storage data directory.
result.add(new StoragePoint(defaultStringDesc,
MainApp.getAppContext().getFilesDir().getAbsolutePath(), StoragePoint.StorageType.INTERNAL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private DisplayUtils() {
*/
public static String bytesToHumanReadable(long bytes) {
if (bytes < 0) {
return MainApp.getAppContext().getString(R.string.common_pending);
return MainApp.string(R.string.common_pending);
} else {
double result = bytes;
int suffixIndex = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public String getDefaultDisplayNameForRootFolder(Context context) {
OCCapability capability = CapabilityUtils.getCapability(context);

if (MainApp.isOnlyOnDevice()) {
return MainApp.getAppContext().getString(R.string.drawer_item_on_device);
return MainApp.string(R.string.drawer_item_on_device);
} else {
if (capability.getServerName() == null || capability.getServerName().isEmpty()) {
return MainApp.getAppContext().getResources().getString(R.string.default_display_name_for_root_folder);
Expand Down

0 comments on commit f4f9f0a

Please sign in to comment.