Migrate from android paging library 2 to paging 3 - java

I am building chat app where i am using Room,ViewModel,PagedListAdapter and it's works perfectly but now i want to upgrade my app to Paging Library 3 which caused real pain. I tried to follow official guide of Android but still not able to migrate from lib 2 to version 3 of paging and most of the tutorial are in kotlin when i am using Java in my project.
I start from changing PagedListAdapter to PagingDataAdapter which cause error at main activity
Chat_ViewModel viewModel = new ViewModelProvider(this).get(Chat_ViewModel.class);
viewModel.chatList.observe(getViewLifecycleOwner(), new Observer<PagedList<ChatEntity_TableColums>>() {
#Override
public void onChanged(PagedList<ChatEntity_TableColums> chatEntity_tableColums) {
Log.d(TAG, "onChanged: Chat Entity = " + chatEntity_tableColums.size());
adapter.submitList(chatEntity_tableColums); // cannot resolve Submitlist
}
});
Then i also tried to upgrade Viewmodel by changing public final LiveData<PagedList<ChatEntity_TableColums>> chatList; to LiveData<PagingData<ChatEntity_TableColums>> chatList; then it cause error in it's constructor,where i cannot find replacement.
public class Chat_ViewModel extends ViewModel {
private static final String TAG = "Chat View Model";
public final LiveData<PagedList<ChatEntity_TableColums>> chatList;
public Chat_ViewModel() {
chatList = new LivePagedListBuilder<>(
ChatRoomDatabase.getInstance(MyApplication.getmContext(),1).chatDAO().getPaginationChat(String.valueOf(Session.getOtherUserID())),20).build();
}
}
This is a query from where i am retrieving the data. I am using default DataSource.Factory to get data from Room
#Query("SELECT * FROM Chat WHERE RECEIVER_USER_ID = :UserID ORDER BY ID DESC") DataSource.Factory<Integer, ChatEntity_TableColums> getPaginationChat(String UserID);
Please guide me bit to update my project into paging library 3 with Java

Related

Bukkit - ShapedRecipe is deprecated

I want to make custom item with custom recipe. I created class with 2 methods, item and customRecipe.
My class looks like this
public class LifeCrystal implements Listener {
private ItemStack item = new ItemStack(Material.DIAMOND);
private ItemMeta meta = item.getItemMeta();
private Plugin plugin = BelieveMe.getPlugin(BelieveMe.class);
public void Item(Player player){
meta.setDisplayName(ChatColor.GOLD + "Life Crystal");
ArrayList<String> lores = new ArrayList<>();
lores.add("Increase your life points");
lores.add("...or revive someone");
meta.setLore(lores);
item.setItemMeta(meta);
}
public void customRecipe(){
ShapedRecipe r = new ShapedRecipe(item);
r.shape(" E ", "LAL", "DGD");
r.setIngredient('E', Material.EMERALD);
r.setIngredient('L', Material.LAPIS_LAZULI);
r.setIngredient('A', Material.GOLDEN_APPLE);
r.setIngredient('D', Material.DIAMOND);
r.setIngredient('G', Material.GOLD_INGOT);
plugin.getServer().addRecipe(r);
}
}
"new ShapedRecipe(item)" is crossed and my error message is "ShapedRecipe is deprecated". I searched for that and find some information about NamespacedKey. I really don't know what to do now
It appears as if you just need to change your ShapedRecipe object constructor (according to the JavaDocs). Changing it to something like:
NamespacedKey nsKey = new NamespacedKey(plugin, "unique_key_here");
ShapedRecipe r = new ShapedRecipe(nsKey, item);
should work on the latest version (1.14.4-R0.1-snapshot at time of writing). There is also a guide written on the official Spigot wiki, linked here.
Quick note: From researching, seems the key HAS to be unique per 1.11 requirements, so make sure you have something that doesn't conflict with any vanilla recipes.

Carrier custom application

I need to create an Android application to set carrier configuration(VoLte e.g.). The application should fetch configs from our Back-End and apply them on the phone.
In Android documentation I found the following article: This article says, that I can create my own application and override CarrierService.
public class SampleCarrierConfigService extends CarrierService {
private static final String TAG = "SampleCarrierConfigService";
public SampleCarrierConfigService() {
Log.d(TAG, "Service created");
}
#Override
public PersistableBundle onLoadConfig(CarrierIdentifier id) {
Log.d(TAG, "Config being fetched");
PersistableBundle config = new PersistableBundle();
config.putBoolean(
CarrierConfigManager.KEY_CARRIER_VOLTE_AVAILABLE_BOOL, true);
config.putBoolean(
CarrierConfigManager.KEY_CARRIER_VOLTE_TTY_SUPPORTED_BOOL, false);
config.putInt(CarrierConfigManager.KEY_VOLTE_REPLACEMENT_RAT_INT, 6);
// Check CarrierIdentifier and add more config if needed…
return config;
}
}
I created an app with this service, but the method onLoadConfig(CarrierIdentifier id) is never called by the system.
So what I want from the system to call my overridden method, not system's. What should I do?
I found your question when researching how to do something similar.
In the article you linked it says:
The carrier app in question must be signed with the same certificate found on the SIM card, as documented in UICC Carrier Privileges.
Since we can't get the certificate from your carrier (they will never give it to you) I think we can't implement our own flavour sadly :-(

Trying to add google maps to a Vaadin view

I'm trying to use the Vaadin GoogleMaps plugin on our web application to show a small window with Google maps. I have this:
private GoogleMap googleMap;
private LatLon mapMarkerlatLon;
private GoogleMapMarker googleMapMarker;
private final String apiKey = "https://maps.googleapis.com/maps/api/js?key=<ourKey>=initMap";
#Override
public void enter(ViewChangeEvent event) {
//googleMap = new GoogleMap(apiKey, null, null);
//As suggested:
googleMap = new GoogleMap(apiKey, null, "english");
mapMarkerlatLon = new LatLon(0,0);
googleMap.setCenter(mapMarkerlatLon);
googleMapMarker = new GoogleMapMarker("Tal", mapMarkerlatLon, false);
googleMap.addMarker(googleMapMarker);
initializeViewContent();
}
A bit further down my class..
protected CssLayout initializeViewContent() {
CssLayout sideBarLayout = new CssLayout();
sideBarLayout.addStyleName("sidebar");
/* ... */
sideBarLayout.addComponent(googleMap);
return sideBarLayout;
}
There's more stuff around the class,but basically this is the "important" bit. When I load the page, I got this:
More or less, translated to english, it says "An error occured. This webpage did not load Google Maps correctly. Discover the technical details on the Javascript console."
EDITED: Firfeox Console is as empyt as my knowledge of this topic.
Chrome's console is telling me about a missing keyMapError.
I've tried changin the key format to:
{ourKey}
{ourKey}=initMap
key={ourKey}=initMap
And, well, I'm getting tired of playing with combinatory. The key works, as it was given to me with a small demo that works flawlessly.
What I'm doing wrong?

App Engine datastore to Android listview

I have set up a basic entity class in my App Engine backend.
`#Entity`
`public class Club {`
`#Id`
`private int id;`
`private String clubName;`
`public Club() {`
`}`
`public int getId() {`
`return id;`
`}`
`public void setId(int id){
this.id =id;
}`
`public String getClubName() {
return clubName;
}`
`public void setClubName(String clubName) {
this.clubName = clubName;
}
}`
I have generated the cloud endpoint class and generated the cloud endpoint library.
I want to be able to populate the clubName from the datastore into a listview in android but not sure how to do this.
I'm trying to follow this https://developers.google.com/appengine/docs/java/endpoints/consume_android but so far I am unable to understand what to do. I'm new to this and would be greatful if anyone lead me in the right direction please.
You can use the below steps to achieve your objective:
1, As mentioned in the google doc on consuming cloud endpoints in android, ready your app by adding the required libraries and make API calls and then on getting data from your backend, you can store that data into a SQL database. You can do this step in the onpostexecute method of your asynch task
protected void onPostExecute(ScoreCollection scores) {
// Do something with the result. maybe the store the data to sqlite database
}
}
To know how to store data in SQLITe database please refer http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html
http://www.vogella.com/articles/AndroidSQLite/article.html
2, Now query data from your SQLITE db into a cursor and then use a simplecursoradapter to display the data from cursor on a listview in your layout or activity screen
An approximate piece of code will have steps like below:
yourcursor = yourdatabase.query; //this is the cursor returned from querying your db
adapter = new SimpleCursorAdapter(this.getActivity(), R.layout.onerowinalistview, yourcursor, FROM, TO,0); // this connects the columns of your DB mentioned in FROM array to the elements in a row of your list as mentioned in TO array
ListView yourlistview = (ListView) view.findViewById(R.id.yourlistview);//this is the listview element in your screen layout
yourlistview.setAdapter(adapter); // setting the adapter to the listview
Hope this helps

how to retrieve info from datastore using google app engine and display it in a list view on an android app using java?

I am trying to make an android app that retrieves info from google app engine datastore and display it as a listview in the android app..can anyone help me out with some code or explain what exactly needs to be done for this purpose? i have already made modifications on the server side to store data on the datastore..what i dont know is how to get that data onto the android app..i am using eclipse indigo and language is java
EDIT : I am putting my code that i am using to retrieve a set of strings from datastore and put it in a list view...the code is gonna look all haywire but i request you to bear with me and explain how exactly to write it..presently the application is force-closing whenever i get to the page where this list of retrieved strings is supposed to be displayed...
public class Display extends ListActivity
{
private LayoutInflater mInflater;
private Vector<RowData> data;
RowData rd;
static String[] title;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.displaylayout);
MyRequestFactory factory = (MyRequestFactory)Util.getRequestFactory(Display.this,MyRequestFactory.class);
FebfourthRequest febfourthRequest = factory.febfourthRequest();
final List<TrialDBProxy> list= new ArrayList<TrialDBProxy>();
febfourthRequest.queryTrialDBs().fire(new Receiver<List<TrialDBProxy>>()
{
#Override
public void onSuccess(List<TrialDBProxy> arg0) {
// TODO Auto-generated method stub
list.addAll(arg0);
}
});
for(int i=0;i<list.size();i++)
{
title[i] = list.get(i).getMessage();
}
mInflater = (LayoutInflater) getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
data = new Vector<RowData>();
for(int i=0;i<title.length;i++)
{
rd = new RowData(i,title[i]);
data.add(rd);
}
int[] to = new int[] { R.id.text1, R.id.text2 };
#SuppressWarnings("deprecation")
Cursor mCursor = this.getContentResolver().query(People.CONTENT_URI, null, null, null, null);
ListAdapter adapter = new SimpleCursorAdapter(this,R.layout.displaylayout,mCursor,title,to);
setListAdapter(adapter);
getListView().setTextFilterEnabled(true);
}
private class RowData
{
protected int mId;
protected String mTitle;
RowData(int id,String title)
{
mId=id;
mTitle = title;
}
#Override
public String toString()
{
return mId+" "+mTitle;
}
} '
NOTE : TrialDB is the file that contains all my fields that i want to store on the datastore.
displaylayout is the xml file where i have created a listview.
i am guessing the main part where i have to put code for displaying stuff is in the onCreate() method.
PLEASE HELP !
This is already a very good starting point for learning both Google App Engine and Android Development.
I may write the steps to follow:
Write a Google App Engine application which reads data from datastore and gives as JSON. You can use GAE web framework, or maybe Django. After doing that, you will have a url which gives you your data in your browser.
Write a hello world application for Android. This step gives you an opportunity to understand and setup Android development environment.
Write an Android app which uses a listview with static data.
Extend your Android app with calling a single simple url from web, then print it on your screen.
Extend your application via calling your Google App Engine application url inside your app. Now you have your datastore data in your app.
Populate your listview with your data.

Categories