Skip to content

Instantly share code, notes, and snippets.

View hosseiniSeyRo's full-sized avatar

R.Hosseini hosseiniSeyRo

  • tehran
View GitHub Profile
@hosseiniSeyRo
hosseiniSeyRo / convert.kt
Created April 14, 2021 08:40
Convert JsonString to Object
fun <T> convertJsonStringToObject(jsonString: String?, objectClass: Class<T>?): T {
return Gson().fromJson(jsonString, objectClass)
}
fun <T> convertJsonStringToObjectList(jsonString: String): List<T> {
return Gson().fromJson(jsonString, object : TypeToken<List<T?>?>() {}.type)
}
const val REQUEST_EXTERNAL_STORAGE = 1001
fun isStoragePermissionGranted(context: Context, activity: Activity): Boolean {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(
context, Manifest.permission.READ_EXTERNAL_STORAGE
) == PackageManager.PERMISSION_GRANTED
) {
// Permission is granted
true
fun convertImageToBase64(imageFile: File): String {
return ByteArrayOutputStream().use { outputStream ->
Base64OutputStream(outputStream, Base64.DEFAULT).use { base64FilterStream ->
imageFile.inputStream().use { inputStream ->
inputStream.copyTo(base64FilterStream)
}
}
return@use outputStream.toString()
}
}
@hosseiniSeyRo
hosseiniSeyRo / circle.xml
Last active April 18, 2020 10:46
drawable
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/numbersCircleBG" />
<size
android:width="120dp"
android:height="120dp" />
</shape>
<application
...
android:theme="@style/AppTheme">
<activity
android:name=".ui.main.MainActivity"
android:label="@string/app_name" />
<activity
android:name=".ui.main.SplashScreenActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="@style/FullscreenTheme">
@hosseiniSeyRo
hosseiniSeyRo / BaseActivity.kt
Created April 18, 2020 08:37
RtL Direction to whole app
open class BaseActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val configuration: Configuration = resources.configuration
configuration.setLayoutDirection(Locale("fa"))
resources.updateConfiguration(configuration, resources.displayMetrics)
}
}
@hosseiniSeyRo
hosseiniSeyRo / SharePrefUtils.java
Last active December 7, 2019 14:01
SharePrefUtils
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;
public class SharePrefUtils {
//list of your keys here
public static final String IS_FIRST_LAUNCH = "is first launch";
@hosseiniSeyRo
hosseiniSeyRo / BaseAdapter.kt
Last active August 19, 2021 05:14
DataBinding BaseAdapter for RecyclerView by Kotlin
abstract class BaseAdapter<T>(private val itemClickListener: OnItemClickListener<T>) :
RecyclerView.Adapter<BaseAdapter<T>.MyViewHolder>() {
interface OnItemClickListener<T> {
fun onItemClick(item: T)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
val binding = DataBindingUtil.inflate<ViewDataBinding>(
LayoutInflater.from(parent.context),
@hosseiniSeyRo
hosseiniSeyRo / CustomeRecyclerViewAdapter
Last active October 1, 2019 13:25
Endless recyclerView+progressBar
public class CustomeRecyclerViewAdapter extends RecyclerView.Adapter<CustomeRecyclerViewAdapter.CustomViewHolder> {
private Context mContext;
private List<T> dataList = new ArrayList<>();
private OnItemClickedListener onItemClickedListener;
// for load more
private final int VIEW_TYPE_ITEM = 0;
private final int VIEW_TYPE_LOADING = 1;
private OnLoadMoreListener onLoadMoreListener;
public class ResponseWrapper<T> {
@NonNull
private Status status;
@Nullable
private T data;
@Nullable
private Integer errorCode;