I am following along with an old Youtube tutorial (which uses Paging 2) in order to learn how to implement an exoPlayer. I have been able to update a lot of the Paging 2 lines given in the video to their corresponding Paging 3 values, but for the life of me I cannot figure out how to replace the LivePagedListBuilder shown in the code below. What is the equivalent of the LivePagedListBuilder in Paging 3?
class MoviePagedListRepository(private val apiService: TheMovieDBInterface) {
lateinit var moviePagedList: LiveData<PagingData<Movie>>
lateinit var moviesDataSourceFactory: MovieDataSourceFactory
#RequiresApi(Build.VERSION_CODES.N)
fun fetchLiveMoviePagedList(compositeDisposable: CompositeDisposable): LiveData<PagingData<Movie>>{
moviesDataSourceFactory = MovieDataSourceFactory(apiService, compositeDisposable)
val config= PagingConfig(
pageSize = POST_PAGE,
enablePlaceholders = false
)
moviePagedList = LivePagedListBuilder(moviesDataSourceFactory, config)
.build()
}
}
I have looked at several sites, including the official Android Developers codelabs site as well sites like Medium and GeeksForGeeks
Related
with vaadin 7 ( we are trying to migrate to v21, very, very, hard) we have this
CustomLayout cl1 = new CustomLayout(new ByteArrayInputStream("<fieldset><legend location='legend'></legend><div location='content'></div></fieldset>".getBytes()));
cl1.setSizeUndefined();
cl1.add(new Label(title), "legend");
cl1.add( panel, "content");
Basically is a panel with border and title-border
How we can do this in vaadin flow v21
Thanks in advance
There's a Cookbook recipe that provides an alternative for CustomLayout: https://cookbook.vaadin.com/custom-layout
Essentially, the CustomLayout replacement class extends Html in a fairly straightforward way. The add method has most of the logic:
public class CustomLayout extends Html {
private Map<String, Component> locations = new HashMap<>();
public CustomLayout(String template) {
super(template);
}
public CustomLayout(InputStream stream) {
super(stream);
}
public void add(Component child, String location) {
remove(location);
locations.put(location, child);
// Establish parent-child relationship, but leave DOM attaching to us
getElement().appendVirtualChild(child.getElement());
// Attach to the specified location in the actual DOM
getElement().executeJs("this.querySelector('[location=\"'+$0+'\"]').appendChild($1)", location,
child.getElement());
// Ensure the element is removed from the DOM when it's detached
child.addDetachListener(detachEvent -> {
detachEvent.unregisterListener();
getElement().executeJs("this.querySelector && this.querySelector('[location=\"'+$0+'\"]').lastChild.remove()", location);
// Also clear the bookkeeping
locations.remove(location, child);
});
}
public void remove(String location) {
Component oldChild = locations.remove(location);
if (oldChild != null) {
remove(oldChild);
}
}
public void remove(Component child) {
getElement().removeVirtualChild(child.getElement());
}
}
Note that it's important to do the bookkeeping with the locations Map so that client-side elements get removed too after the parent is detached.
Vaadin 10+ defines "elements" for most commonly used HTML tags, and has higher level abstractions for components built on top of those elements. It does not include an element or a component for <fieldset>. I'm not familiar with Vaadin 7, but it looks like it didn't come with it either.
There are a couple of ways to do what you want with Vaadin 10+. Here's a quick example based on extending the Component class:
#Tag("fieldset")
public class FieldSet extends Component {
private final Div enclosedComponents;
public FieldSet(String label) {
Element legend = new Element("legend").setText(label);
getElement().appendChild(legend);
enclosedComponents = new Div();
getElement().appendChild(enclosedComponents.getElement());
}
public void add(Component ... components) {
enclosedComponents.add(components);
}
}
I did not include a robust API. It would be more useful with a full compliment of add and remove methods, as well as a means to update the label.
As a point of learning 10+, know that the nature of fieldset makes this one more complicated. If this did not have to include the <legend> tag it could be far simpler, because you could simply extend Div or one of the several Layout classes and inherit a robust API.
There is a section of the documentation that outlines the various ways to solve these types of problems. I found it invaluable when I first started using Vaadin. It's not always clear when to use each of the approaches, but you'll get the feel for it.
I have a ExerciseDetailFragment that contains an ExerciseFragmentStatePagerAdapter to show a bunch of SupportUsFragmentCard. These cards can be swiped horizontally by the user.
In my ExerciseFragmentStatePagerAdapter I have the following code:
fun createFragment(position: Int): Fragment {
val exercise = exercises[position]
val card = SupportUsFragmentCard()
card.setExercise(exercise) <---- this is my question/problem
return card
}
As you can see the pager adapter just instantiates the SupportUsFragmentCard and for this the exercise needs to be passed along (the card displays some exercise information) via the setExercise.
The SupportUsFragmentCard looks like this:
open class SupportUsFragmentCard : RootFragment() {
...
val viewModel: SupportUsViewModel by viewModels()
...
fun setExercise(exercise: Exercise?) {
viewModel.setExercise(exercise) <---- passes on the exercise to the viewModel
}
It’s implementation passes along the exercise to the underlying viewModel. Which in its turn encapsulates this into a LiveData (on which the SupportUsFragmentPlain has observers but I omitted this code as its not the issue):
class SupportUsViewModel() : ViewModel() {
//interface to the view
fun getExercise(): LiveData<Exercise?> = exercise
fun setExercise(execise: Exercise?) {
exercise.value = execise. <--- updates the Livedata object
}
//underlying live data mutable values
private val exercise = MutableLiveData<Exercise?>(null)
}
When this code is executed, it crashes with exception:
IllegalStateException: Can't access ViewModels from detached fragment
I think because the createFragment ends up updating the viewModel without actually already being on screen. I also feel that this way of working does not respect the MVVM architecture.
What is the correct way in this scenario, using MVVM and LiveData to initialise the SupportUsViewModel with an Exercise in the ExerciseFragmentStatePagerAdapter's createFragment function?
Good afternoon. I have reports with parameters, before forming reports, I would like to make a preview. How to use "webReport.Report.ShowPrepared ()"?
item = reportDB.SelectFirst(Convert.ToInt64(showID));
reportDB.SelectBinaryFile(ref item);
var r = new FastReport.Report();
r.LoadFromString(Encoding.UTF8.GetString(item.ReportBody));
WebReport webReport = new WebReport();
webReport.Width = Unit.Percentage(100);
webReport.Height = Unit.Percentage(100);
if (1==1)//проверка на рус язык
webReport.LocalizationFile = "~\\Translation\\Russian.frl";
SetUserInfo(ref r);
webReport.AutoWidth = true;
webReport.AutoHeight = true;
webReport.Report =r;
webReport.PrevPage();
ViewBag.WebReport = webReport.GetHtml();
As per the official documentation if Fast reports you can use like below.
First you needs to check whether the report is prepared, if prepared returns true boolean value simply you can call the showprepared() method.
webReport.Load("report1.frl");
webReport.Prepare(true);
webReport.ShowPrepared();
if you wants to use some modal window and needs to return to the privious pages then you can use it like below.
void ShowPrepared(bool modal,Form owner)
The same as the previous method. The ow ner parameter determines a
window that owns the preview window.
Please read more from here to implement it in better way.
Official Documentation Fast Reports
I try to implement in-app purchase functionalities with several permanent items in Swift 3 for my spritekit game. Everything is created on iTunes Connect, the bundle name is set and my 4 items are correctly declared in the iTunes Connect. The problem is about code inside Xcode. I use the tutorial from Raywenderlich.com here:
https://www.raywenderlich.com/122144/in-app-purchase-tutorial
This tutorial is made for just one item, but what about if we need more items ? (4 in my case). I try for 2 days to modify the code to manage more than one single item, without any success. I have modified the structure RageProducts with the following code:
import Foundation
public struct RageProducts {
public static let GirlfriendOfDrummerRage = "com.creaworks.FurryLight_Puzzles.Guitarist"
fileprivate static let productIdentifiers: Set<ProductIdentifier> = [RageProducts.GirlfriendOfDrummerRage]
// Initial declaration for one item
// public static let store = IAPHelper(productIds: RageProducts.productIdentifiers)
}
//New declaration for 4 items
public static let store = IAPHelper(productIds: Set(
[
GreenGrocerPurchase.AdRemoval,
GreenGrocerPurchase.NewShoppingLists_One,
GreenGrocerPurchase.NewShoppingLists_Five,
GreenGrocerPurchase.NewShoppingLists_Ten
].map { $0.productId }
))
func resourceNameForProductIdentifier(_ productIdentifier: String) -> String? {
return productIdentifier.components(separatedBy: ".").last
}
When I test the code, the compiler return no error but I see no item in my purchase list (instead of one when I activate the old one item declaration). What am I missing?
Is there a swift 3 simplest code example to declare several items for in app purchase ? I can't find any on the web. I use spritekit, so, I don't need tableview components or UIView buttons, this is a little bit confusing for just starting with in app purchase functionalities.
Make sure you add additional identifiers, similar to this one:
public static let GirlfriendOfDrummerRage = "com.creaworks.FurryLight_Puzzles.Guitarist"
Then add them to Set<ProductIdentifier>.
Here an example with 2 products:
public struct Products {
public static let One = "com.creaworks.FurryLight_Puzzles.Guitarist"
public static let Two = "com.creaworks.FurryLight_Puzzles.GuitaristTWO"
fileprivate static let productIndentifiers: Set<ProductIdentifier> = [Products.One, Products.Two]
func resourceNameForProductIdentifier(_ productIdentifier: String) -> String? {
return productIdentifier.components(separatedBy: ".").last
}
}
I've been trying for hours to get something as simple as displaying a line chart based on 2 dots that I supply manually and all I get is a crash. I've tried to understand how everything works based on the demo code but it's too complex. I'm not even concerned about writing nice code with onResume() etc, I just want something to display the first time I open the activity. Once I know how to do that I'll be able to adapt and learn what I need. Here's the code I came up with:
public class StatsActivity extends Activity {
private XYMultipleSeriesDataset StatsDataset = new XYMultipleSeriesDataset();
private XYMultipleSeriesRenderer StatsRenderer = new XYMultipleSeriesRenderer();
private XYSeries StatsCurrentSeries;
private GraphicalView StatsChartView;
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.stats);
LinearLayout layout = (LinearLayout) findViewById(R.id.Statschart);
StatsRenderer.setAxesColor(Color.YELLOW);
String seriesTitle = "Rank";
XYSeries series = new XYSeries(seriesTitle);
series.add(5, 7); //1st series I want to add
StatsDataset.addSeries(series);
series.add(9, 1); //the 2nd one
StatsDataset.addSeries(series);
StatsCurrentSeries = series;
System.out.println(series);
XYSeriesRenderer renderer = new XYSeriesRenderer();
renderer.setColor(Color.RED);
StatsRenderer.addSeriesRenderer(renderer);
StatsChartView = ChartFactory.getLineChartView(this, StatsDataset,StatsRenderer);
layout.addView(StatsChartView);
}
}
I've been reading the docs to determine what each function does but in the end I still can't get anything to display.
Thanks!
The big thing that I struggled with is that you need a renderer for each XYSeries. You have two series here, but just one renderer - I just create/add renderers when I input data. Also, Android is mostly pass-by-reference, so you've passed the same data set in twice (i.e. your second update to the data will be mirrored "in" the MultipleSeriesDataset).