Skip to content

Instantly share code, notes, and snippets.

View ashishrawat2911's full-sized avatar
🥶

Ashish Rawat ashishrawat2911

🥶
View GitHub Profile
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
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) {
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);
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);
}
});
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
public class Photographer {
String photoGrapherName;
String photographerImageUrl;
public Photographer(String photoGrapherName, String photographerImageUrl) {
this.photoGrapherName = photoGrapherName;
this.photographerImageUrl = photographerImageUrl;
}
public String getPhotoGrapherName() {
class Article {
Source source;
String author;
String title;
String description;
String url;
String urlToImage;
String publishedAt;
String content;
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;
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 {
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;