This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun <reified T> Context.getJsonGenericKotlin(@RawRes jsonFileRes: Int): T { | |
val inputStream = this.resources.openRawResource(jsonFileRes) | |
val bufferReader = BufferedReader(InputStreamReader(inputStream)) | |
return gson.fromJson(bufferReader, T::class.java) | |
} | |
// วิธีเรียกใช้ | |
getJsonGenericKotlin<MyDataModel>(R.raw.json_text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun Context.getJsonGenericKotlin(@RawRes jsonFileRes: Int): T { | |
val inputStream = this.resources.openRawResource(jsonFileRes) | |
val bufferReader = BufferedReader(InputStreamReader(inputStream)) | |
return gson.fromJson(bufferReader, T::class.java) | |
} | |
// วิธีเรียกใช้ | |
getJsonGenericKotlin<MyDataModel>(R.raw.json_text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun MyDataModel Context.getJsonFixModelClassKotlin(@RawRes jsonFileRes: Int): MyDataModel { | |
val inputStream = this.resources.openRawResource(jsonFileRes) | |
val bufferReader = BufferedReader(InputStreamReader(inputStream)) | |
return gson.fromJson(bufferReader, MyDataModel::class.java) | |
} | |
// วิธีเรียกใช้ | |
getJsonFixModelClassKotlin(R.raw.json_text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static T getJsonClassParameter(Context context, @RawRes int jsonFileRes, Class<T> classType) { | |
Gson gson = new Gson(); | |
InputStream inputStream = context.getResources().openRawResource(jsonFileRes); | |
BufferedReader bufferReader = new BufferedReader(new InputStreamReader(inputStream)); | |
return gson.fromJson(bufferReader, classType); | |
} | |
// วิธีเรียกใช้ | |
GenericJava.getJsonClassParameter(this, R.raw.json_text, MyDataModel.class) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static <T> T getMyDataModel(Context context, @RawRes int jsonFileRes) { | |
Type type = new TypeToken<T>(){}.getType(); | |
Gson gson = new Gson(); | |
InputStream inputStream = context.getResources().openRawResource(jsonFileRes); | |
BufferedReader bufferReader = new BufferedReader(new InputStreamReader(inputStream)); | |
return gson.fromJson(bufferReader, type); | |
} | |
// วิธีเรียกใช้ | |
GenericJava.getMyDataModel<MyDataModel>(this, R.raw.json_text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"lastUpload":"2019-07-22T03:27:42.601Z","extensionVersion":"v3.4.0"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity { | |
static { | |
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); | |
} | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class User { | |
@Expose | |
String name; | |
@Expose | |
String blog; | |
@Expose | |
String company; | |
public String getName() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<uses-permission android:name="android.permission.INTERNET" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface OnNetworkCallbackListener{ | |
public void onResponse(User user, Retrofit retrofit); | |
public void onBodyError(ResponseBody responseBodyError); | |
public void onBodyErrorIsNull(); | |
public void onFailure(Throwable t); | |
} |
NewerOlder