moved static functions to util class

This commit is contained in:
Elad Keyshawn 2017-04-06 13:12:50 +02:00
parent ab5155b1d3
commit c827a50f05
3 changed files with 4 additions and 45 deletions

View File

@ -52,6 +52,7 @@ import org.kiwix.kiwixmobile.database.RecentSearchDao;
import org.kiwix.kiwixmobile.utils.LanguageUtils;
import org.kiwix.kiwixmobile.utils.StyleUtils;
import org.kiwix.kiwixmobile.views.SliderPreference;
import org.kiwix.kiwixmobile.zim_manager.library_view.LibraryUtils;
import static org.kiwix.kiwixmobile.utils.StyleUtils.dialogStyle;
@ -165,7 +166,7 @@ public class KiwixSettingsActivity extends AppCompatActivity {
getPrefrence(PREF_STORAGE).setTitle(PreferenceManager.getDefaultSharedPreferences(getActivity())
.getString(KiwixMobileActivity.PREF_STORAGE_TITLE, "External"));
}
getPrefrence(PREF_STORAGE).setSummary(LibraryFragment.bytesToHuman( new File(PreferenceManager.getDefaultSharedPreferences(getActivity())
getPrefrence(PREF_STORAGE).setSummary(LibraryUtils.bytesToHuman( new File(PreferenceManager.getDefaultSharedPreferences(getActivity())
.getString(KiwixMobileActivity.PREF_STORAGE, Environment.getExternalStorageDirectory().getPath())).getFreeSpace()));
}
}

View File

@ -219,7 +219,7 @@ public class LibraryFragment extends Fragment
< Long.parseLong(((Book) (parent.getAdapter().getItem(position))).getSize()) * 1024f) {
Toast.makeText(super.getActivity(), getString(R.string.download_no_space)
+ "\n" + getString(R.string.space_available) + " "
+ bytesToHuman(getSpaceAvailable()), Toast.LENGTH_LONG).show();
+ LibraryUtils.bytesToHuman(getSpaceAvailable()), Toast.LENGTH_LONG).show();
Snackbar snackbar = Snackbar.make(libraryList,
getString(R.string.download_change_storage),
Snackbar.LENGTH_LONG)
@ -271,44 +271,6 @@ public class LibraryFragment extends Fragment
}
}
public static String bytesToHuman(long size) {
long KB = 1024;
long MB = KB * 1024;
long GB = MB * 1024;
long TB = GB * 1024;
long PB = TB * 1024;
long EB = PB * 1024;
if (size < KB) {
return size + " Bytes";
}
if (size >= KB && size < MB) {
return round3SF((double) size / KB) + " KB";
}
if (size >= MB && size < GB) {
return round3SF((double) size / MB) + " MB";
}
if (size >= GB && size < TB) {
return round3SF((double) size / GB) + " GB";
}
if (size >= TB && size < PB) {
return round3SF((double) size / TB) + " TB";
}
if (size >= PB && size < EB) {
return round3SF((double) size / PB) + " PB";
}
if (size >= EB) {
return round3SF((double) size / EB) + " EB";
}
return "???";
}
public static String round3SF(double size) {
BigDecimal bd = new BigDecimal(size);
bd = bd.round(new MathContext(3));
return String.valueOf(bd.doubleValue());
}
public void mobileDownloadDialog(int position, AdapterView<?> parent) {
new AlertDialog.Builder(super.getActivity(), dialogStyle())

View File

@ -1,9 +1,5 @@
package org.kiwix.kiwixmobile.zim_manager.library_view;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import java.math.BigDecimal;
import java.math.MathContext;
@ -11,7 +7,7 @@ import java.math.MathContext;
* Created by EladKeyshawn on 06/04/2017.
*/
public class UtilFunctions {
public class LibraryUtils {
public static String bytesToHuman(long size) {
long KB = 1024;
long MB = KB * 1024;