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
dependencies { | |
//adding dependencies | |
implementation 'com.android.support:recyclerview-v7:27.1.1' | |
implementation 'com.squareup.retrofit2:retrofit:2.4.0' | |
implementation 'com.squareup.retrofit2:converter-gson:2.4.0' | |
implementation 'com.github.bumptech.glide:glide:4.3.1' | |
annotationProcessor 'com.github.bumptech.glide:compiler:4.3.1' | |
//Android Jetpack |
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 PhotographerAdapter extends RecyclerView.Adapter<PhotographerAdapter.PhotoViewHolder> { | |
Context mCtx; | |
List<Photographer> photographersList; | |
public PhotographerAdapter(Context mCtx, List<Photographer> photographersList) { | |
this.mCtx = mCtx; | |
this.photographersList= photographersList; | |
} | |
@NonNull | |
@Override | |
public PhotoViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { |
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 { | |
RecyclerView recyclerView; | |
PhotographerAdapter adapter; | |
List<Photographer> photographersList; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
recyclerView = findViewById(R.id.recyclerview); | |
recyclerView.setHasFixedSize(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
PhotographersViewModel model = ViewModelProviders.of(this).get(PhotographersViewModel.class); | |
model.getPhotographer().observe(this, new Observer<List<Photographer>>() { | |
@Override | |
public void onChanged(@Nullable List<Photographer> photographerList) { | |
adapter = new PhotographerAdapter(MainActivity.this, photographerList); | |
recyclerView.setAdapter(adapter); | |
} | |
}); |
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 PhotographersViewModel extends ViewModel { | |
//this is the data that we will fetch asynchronously | |
private MutableLiveData<List<Photographer>> photographerList; | |
//we will call this method to get the data | |
public LiveData<List<Photographer>> getPhotographer() { | |
//if the list is null |
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 Photographer { | |
String photoGrapherName; | |
String photographerImageUrl; | |
public Photographer(String photoGrapherName, String photographerImageUrl) { | |
this.photoGrapherName = photoGrapherName; | |
this.photographerImageUrl = photographerImageUrl; | |
} | |
public String getPhotoGrapherName() { |
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
class Article { | |
Source source; | |
String author; | |
String title; | |
String description; | |
String url; | |
String urlToImage; | |
String publishedAt; | |
String content; |
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
Future<List<Article>> getData(String newsType) async { | |
List<Article> list; | |
String link = | |
"https://newsapi.org/v2/top-headlines?country=in&apiKey=API_KEY"; | |
var res = await http | |
.get(Uri.encodeFull(link), headers: {"Accept": "application/json"}); | |
print(res.body); | |
if (res.statusCode == 200) { | |
var data = json.decode(res.body); | |
var rest = data["articles"] as List; |
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
import 'dart:async'; | |
import 'dart:convert'; | |
import 'package:flutter/material.dart'; | |
import 'package:flutter_news_web/model/news.dart'; | |
import 'package:flutter_news_web/news_details.dart'; | |
import 'package:http/http.dart' as http; | |
class NewsListPage extends StatefulWidget { | |
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
package adhoc.successive.com.flutteralertdemo; | |
import android.app.Activity; | |
import android.app.Dialog; | |
import io.flutter.plugin.common.MethodCall; | |
import io.flutter.plugin.common.MethodChannel; | |
import io.flutter.plugin.common.MethodChannel.MethodCallHandler; | |
import io.flutter.plugin.common.MethodChannel.Result; | |
import io.flutter.plugin.common.PluginRegistry.Registrar; |
OlderNewer